Index creating method and device in distributed system
By using coordination nodes to manage non-asynchronous updates of metadata in distributed databases, the problem of difficult performance and availability during the creation of global secondary indexes in distributed databases is solved, and an efficient and reliable index creation process is achieved.
Patent Information
- Application Number
- CN202310916238.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-24
- Publication Date
- 2025-01-24
AI Technical Summary
In distributed databases, it is difficult for the prior art to efficiently create global secondary indexes without blocking DML transaction processing of user services, and it is difficult to ensure high performance or high availability during the creation process.
By implementing metadata non -exotic update mechanisms on coordinated nodes, coordinating nodes notify multiple other nodes to configure the metadata of the global second -level index, and after all nodes complete the metadata configuration and version update, synchronize your own metadata configuration and the configuration and version of it The version update.
While creating a global second -level index online in a distributed system, the high performance and high availability of the creation process are guaranteed, and an additional burden caused by fixing a node execution index creation is avoided.
Smart Images

Figure CN119357179A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for creating an index in a distributed system. Background Art
[0002] A distributed system is composed of a number of stations. These stations are also called nodes or agents, which are connected together in a communication network. Each node is an independent database system, including its own database, central processing unit, terminal and local database management system. It can be regarded as a combination of a series of centralized database systems, which belong to the same system logically but are distributed in physical structure.
[0003] In a distributed database, the data in each data table can be distributed and stored on multiple different nodes after being partitioned or sharded according to certain rules. The data here can be multiple records in the data table, and the records assigned to the node are managed by the database instance running on each node. For example, a column or multiple columns in a data table are used as the columns of the distribution key of the data table, and then the data in the data table is partitioned or sharded according to the hash value of the distribution key column. Then the data in the partitioned or sharded data table is stored on multiple different nodes according to the distribution key.
[0004] At present, when querying data in a database, if the query is based on the distribution key of the data table, the expected user data can be quickly found. However, if the query is based on any other column other than the distribution key, the query request needs to be sent to all nodes to aggregate the results returned by all nodes to obtain the final query result. For a large-scale distributed system with many nodes, the entire query process needs to establish network communication with a large number of nodes, resulting in low query efficiency. Therefore, it is necessary to introduce a global secondary index (GSI) to support queries based on other columns of the data table, so that the distributed database supports more flexible query capabilities in more dimensions. Among them, the global secondary index is a global index that takes effect on the data nodes in the distributed database, which can be created according to the specific needs of the user. However, in order to avoid blocking the data manipulation language (DML) transaction processing of the user's business, the creation of the global secondary index GSI is usually performed online, but the high performance or high availability (HA) during the creation process is difficult to guarantee. Summary of the invention
[0005] The present application provides a method and device for creating an index in a distributed system, which can realize online creation of a global secondary index GSI in the distributed system while ensuring high performance or high availability during the creation process.
[0006] In order to achieve the above purpose, this application adopts the following technical solutions:
[0007] In a first aspect, a method for creating an index in a distributed system is provided, which is applied to a coordination node in the distributed system, and the distributed system also includes multiple other nodes. The method includes: in the online creation process of a global secondary index, notifying multiple other nodes to configure metadata of the global secondary index, wherein the metadata includes a metadata version configured for updating and / or generating metadata; when the coordination node meets preset conditions, configuring the metadata of the global secondary index on the coordination node.
[0008] Among them, the online creation of the global secondary index can be understood as the DML transaction processing of user business can be carried out in parallel during the creation of the global secondary index without blocking each other.
[0009] The coordination node can be any coordination node in the distributed system that receives an online creation request for a global secondary index. When there is another coordination node in the distributed system that receives an online creation request for a new global secondary index, the other coordination node can also execute the index creation method in the distributed system provided by the above solution.
[0010] Optionally, the multiple other nodes notified by the above-mentioned coordinating node may include data nodes, and may also include other coordinating nodes.
[0011] Optionally, during the online creation of a global secondary index, in order to ensure the consistency of the metadata of the global secondary index, the metadata needs to transition through multiple version states from the start of creation to the completion of creation of the global secondary index. As an example, from the start of creation to the completion of creation of the global secondary index, the metadata transitions through multiple version states, namely: initial (absent), deletable but not readable or writable (delete only), writable but not readable (write only (data reorganization)), available (public), etc. As another example, the version states of metadata transition can also be simplified, such as from the start of creation to the completion of creation of the global secondary index, the version states of metadata transition can include only absent, write only (data reorganization), and public.
[0012] Optionally, the preset condition satisfied by the coordinating node may be a condition that can confirm that each of the multiple other nodes has completed the metadata configuration of the global secondary index. In this way, the coordinating node can confirm whether each of the multiple other nodes has completed the metadata configuration of the global secondary index by judging whether the preset condition is satisfied.
[0013] In the solution provided by the first aspect above, the coordination node is directly responsible for the entire online creation process of the global secondary index, and during the online creation process of the global secondary index, the coordination node first notifies multiple other nodes to configure the metadata of the global secondary index, and then synchronously configures the metadata of the global secondary index itself. This solution can realize the online creation of the global secondary index based on the synchronous update of metadata (non-asynchronous update) while ensuring the global consistency of metadata. And because the node that executes the online creation of the global secondary index in this solution is not a specific node, but any coordination node in the distributed system can execute it. In this way, there will be no frequent increase in additional burden on the node due to the fixed node executing the online creation of the global secondary index, and there is no need to introduce a third-party node / tool with high concurrent access load to coordinate metadata updates. In this way, during the online creation process of the global secondary index, the concurrent high performance under a large-scale cluster can be effectively guaranteed.
[0014] In a possible implementation, the preset condition satisfied by the above-mentioned coordination node may be: receiving completion feedback information returned by each of the multiple other nodes. In this way, in the online creation process of the global secondary index, when the coordination node notifies multiple other nodes to complete the metadata configuration, each of the multiple other nodes can return an indication message to the coordination node when completing the corresponding metadata configuration, so that the coordination node can promptly confirm that the multiple other nodes have completed the metadata configuration. It can be understood that this is not limited to the metadata generation stage or the update stage, or the waiting stage for all DML transactions. Each of the multiple other nodes can return an indication message to the coordination node after completing the corresponding operation.
[0015] In a possible implementation, the preset condition satisfied by the above-mentioned coordination node may also be: waiting for a preset processing time. In this way, in the online creation process of the global secondary index, when the coordination node notifies multiple other nodes to complete the metadata configuration, it can be assumed that multiple other nodes have completed the corresponding metadata configuration after waiting for a certain period of time, thereby realizing automatic confirmation of the completion of the metadata configuration of multiple other nodes. It can be understood that this is not limited to the metadata generation stage or the update stage, or the waiting stage for all DML transactions. The coordination node can automatically confirm that multiple other nodes have completed the configuration after waiting for a certain period of time after the notification.
[0016] In a possible implementation, the distributed system also includes a client. When the above configuration is used to generate metadata, the above process of generating metadata of the global secondary index during the online creation of the global secondary index may include: receiving an index creation request from the client, the index creation request is used to indicate the online creation of a global secondary index associated with a field on a data table; in response to the index creation request, notifying multiple other nodes to create and initialize metadata of the global secondary index, and setting the metadata version of the global secondary index to the first version; when the coordination node meets the preset conditions, creating and initializing metadata of the global secondary index on the coordination node, and setting the metadata version of the global secondary index to the first version.
[0017] Optionally, the preset condition satisfied by the above-mentioned coordination node may be: receiving setting feedback information returned by each of the multiple other nodes. The setting feedback information returned by each node may be used to indicate that the creation and initialization of the metadata of the global secondary index on its node and the setting of the first version have been completed.
[0018] In this way, during the online creation of the global secondary index, the coordination node can notify and wait for multiple other nodes to complete the initialization of metadata and the setting of metadata version in the metadata generation phase (initialization phase) of the global secondary index, and then synchronously complete the initialization of metadata and the setting of metadata version on its own node (i.e., the coordination node that executes the index creation method of this scheme). In this way, the coordination node is used to implement the metadata initialization of the non-asynchronous mechanism during the online creation of the global secondary index, which not only ensures the global consistency of metadata, but also ensures the concurrent high performance under large-scale clusters.
[0019] Optionally, the first version may be a starting version set in the metadata initialization phase, which may be a write-only version or a delete-only version. This solution does not limit this, and it may be other versions.
[0020] In one possible implementation, when the above configuration is used to update metadata, the above-mentioned process of updating the metadata of the global secondary index during the online creation of the global secondary index may include: when the coordinating node and multiple other nodes have completed the first version setting of the metadata version in the metadata of the global secondary index, notifying multiple other nodes to update the metadata version from the first version to the second version; when the coordinating node meets the preset conditions, updating the metadata version from the first version to the second version on the coordinating node.
[0021] Optionally, the preset condition satisfied by the above-mentioned coordination node may be: receiving update feedback information returned by each of the multiple other nodes, wherein the update feedback information returned by each node may be used to indicate that the second version update of the metadata version of the global secondary index on its node has been completed.
[0022] In this way, during the online creation of the global secondary index, the coordination node can first notify and wait for multiple other nodes to complete the metadata update and metadata version update, and then synchronously complete the metadata update and metadata version update on its own node during the metadata update phase of the global secondary index. In this way, the coordination node is used to implement the metadata update of the non-asynchronous mechanism during the online creation of the global secondary index, which not only ensures the global consistency of metadata, but also ensures the concurrent high performance under large-scale clusters.
[0023] Optionally, the second version may be an intermediate compatible version set in the metadata update phase, which is not limited in this solution, such as a write-only version. The first version may be the previous version before the second version, which may be the starting version set in the metadata initialization phase, or the previous intermediate compatible version. For example, when the second version to be updated is a write-only version, the previous version may be a delete-only version.
[0024] In a possible implementation, when the above configuration is used to update metadata and the global secondary index is available after the update, the above-mentioned process of updating the metadata of the global secondary index during the online creation of the global secondary index may also include: when the coordination node and multiple other nodes have completed the first version setting of the metadata version in the metadata of the global secondary index, filling the relevant data in the data table into the global secondary index; when confirming that the data filling of the global secondary index is completed, notifying multiple other nodes to update the metadata version from the first version to the second version; when the coordination node meets the preset conditions, updating the metadata version from the first version to the second version on the coordination node.
[0025] Optionally, the preset condition satisfied by the above-mentioned coordination node may be: receiving update feedback information returned by each of the multiple other nodes, wherein the update feedback information returned by each node may be used to indicate that the update of the metadata version of the global secondary index on its node has been completed.
[0026] In this way, in the process of online creation of the global secondary index, the coordination node can enter the final metadata update phase of the global secondary index after completing the data filling of the global secondary index, to indicate that the global secondary index is successfully created and is available. In the final metadata update phase of the global secondary index, the coordination node first notifies and waits for multiple other nodes to complete the final update of metadata and the final update of metadata version, and then synchronously completes the final update of metadata and the final update of metadata version on its own node. In this way, the coordination node is used to implement the final metadata update of the non-asynchronous mechanism in the process of online creation of the global secondary index, which not only ensures the global consistency of metadata, but also ensures the concurrent high performance under large-scale clusters.
[0027] Optionally, the second version may be the final version set in the metadata update phase, which is not limited in this solution, such as a publicly available version. This version status is used to indicate that the global secondary index is successfully created and is in an available state. The first version may be the previous version before the second version, which may be the starting version set in the metadata initialization phase or the previous intermediate compatible version. For example, when the second version to be updated is an available version, the previous version may be a write-only version.
[0028] In a possible implementation, after the above-mentioned coordination node and multiple other nodes complete the first version setting of the metadata version in the metadata of the global secondary index, the index creation method in the distributed system of the present application may also include: waiting for all transactions of the data table on the coordination node and multiple other nodes to end. Then the coordination node executes the subsequent process. In this way, in the online creation process of the global secondary index, the coordination node can update all nodes (including the coordination node and multiple other nodes) to enter version V. n After that, it will enter the waiting stage for the user's DML transaction to complete, waiting for all currently active DML transactions to complete. Then it will update to the next version V n+1 In this way, during the online creation of global secondary indexes, the coordination node can follow the principle of user DML transaction priority and complete the asynchronous update of metadata. This not only ensures the consistency of base table and index data under the asynchronous metadata update mechanism, but also does not hinder the normal execution of user DML transactions, ensuring high availability during the creation process.
[0029] Optionally, when all transactions of the data table on the coordinating node and multiple other nodes are completed, the coordinating node may execute the aforementioned subsequent process again. For example, when all transactions of the data table on the coordinating node and multiple other nodes are completed, the coordinating node notifies multiple other nodes to update the metadata of the global secondary index, and updates the metadata version of the global secondary index from the first version to the second version. Alternatively, when all transactions of the data table on the coordinating node and multiple other nodes are completed, the coordinating node fills the relevant data in the data table into the global secondary index.
[0030] In a possible implementation, the distributed system also includes a client, and the above-mentioned preset condition includes a first preset condition and a second preset condition. When the above-mentioned configuration is used to generate and update metadata, the above-mentioned process of generating and updating metadata of the global secondary index in the online creation process of the global secondary index includes: receiving an index creation request from the client, the index creation request is used to indicate the online creation of a global secondary index associated with a field on the data table; in response to the index creation request, notifying multiple other nodes to create and initialize the metadata of the global secondary index, and setting the metadata version of the global secondary index to the first version, the first version is used to indicate that the global secondary index is writable but not readable; when the coordination node meets the first preset condition, creating and initializing the metadata of the global secondary index on the coordination node, and setting the metadata version of the global secondary index to the first version; after waiting for all transactions of the data table on the coordination node and multiple other nodes to be completed, filling the relevant data in the data table into the global secondary index; when the data filling of the global secondary index is completed, notifying multiple other nodes to update the metadata version from the first version to the second version, the second version is used to indicate that the global secondary index is normally available; when the coordination node meets the second preset condition, updating the metadata version from the first version to the second version on the coordination node.
[0031] Optionally, the first preset condition satisfied by the above-mentioned coordination node may be: receiving setting feedback information returned by each of the multiple other nodes. The setting feedback information returned by each node may be used to indicate that the first version setting of the metadata version of the global secondary index on its node has been completed.
[0032] Optionally, the second preset condition satisfied by the above-mentioned coordination node may be: receiving update feedback information returned by each of the multiple other nodes, wherein the update feedback information returned by each node may be used to indicate that the second version update of the metadata version of the global secondary index on its node has been completed.
[0033] In this way, in the process of online creation of the global secondary index, the coordinating node can complete the initialization of the metadata and the setting of the metadata version of multiple other nodes and its own node by using the aforementioned non-asynchronous mechanism, wait for all transactions of the data tables on the coordinating node and multiple other nodes to end, and directly enter the data filling stage to generate the global secondary index. After the data filling is completed, the aforementioned non-asynchronous mechanism is directly used to complete the final update of the metadata and metadata version of multiple other nodes and its own node. The entire creation process only requires the state transition of two metadata versions. Therefore, this solution not only realizes the non-asynchronous update of metadata during the online creation of the global secondary index by using the coordinating node, but also simplifies the metadata version transition process, while still ensuring the global consistency of metadata, and also ensuring high performance and high availability during the creation process.
[0034] In one possible implementation, the above-mentioned waiting for all transactions on the data table on the coordinating node and multiple other nodes to be completed includes: notifying multiple other nodes to wait for all unfinished transactions on the data table to be completed; when the coordinating node meets specified conditions, waiting for all unfinished transactions on the data table on the coordinating node to be completed.
[0035] Optionally, the specified condition satisfied by the above-mentioned coordination node may be: receiving waiting feedback information returned by each of the multiple other nodes, wherein the waiting feedback information returned by each node may be used to indicate that all unfinished transaction waits on the data table have been completed on its node.
[0036] In this way, during the online creation of the global secondary index, the coordinating node can wait for all currently active DML transactions to complete in a non-asynchronous manner, that is, first notify and wait for multiple other nodes to complete all DML transactions, and then synchronously complete all DML transactions on its own node.
[0037] In a possible implementation, the notifying multiple other nodes to configure the metadata of the global secondary index includes: sending a structured query language SQL instruction to the multiple other nodes, where the SQL instruction is used to instruct the multiple other nodes to configure the metadata of the global secondary index. In this way, in the online creation process of the global secondary index, the coordinating node can directly guide the multiple other nodes to complete the metadata configuration of the global secondary index through the SQL instruction.
[0038] In a second aspect, a distributed system is provided, the distributed system comprising a coordination node and a plurality of other nodes, wherein:
[0039] A coordinating node, used to send instructions to multiple other nodes during the online creation process of the global secondary index, the instructions are used to instruct the multiple other nodes to configure metadata of the global secondary index, the metadata including a metadata version, configured to update and / or generate metadata;
[0040] Each of the multiple other nodes is used to receive the instruction, respond to the instruction, and configure the metadata of the global secondary index on its own node;
[0041] The coordination node is also used to configure metadata of the global secondary index on the coordination node when the coordination node meets preset conditions.
[0042] The coordination node may be any coordination node in the distributed system that receives an online creation request for a global secondary index. Optionally, the multiple other nodes notified by the coordination node may include data nodes or other coordination nodes.
[0043] Optionally, the preset condition satisfied by the coordinating node may be a condition that can confirm that each of the multiple other nodes has completed the metadata configuration of the global secondary index. In this way, the coordinating node can confirm whether each of the multiple other nodes has completed the metadata configuration of the global secondary index by judging whether the preset condition is satisfied.
[0044] The solution provided in the second aspect above is for a distributed system including a coordination node and multiple other nodes, and any coordination node can be directly responsible for the entire online creation process of the global secondary index. And in the online creation process of the global secondary index, the coordination node instructs multiple other nodes to perform the configuration operation of the metadata of the global secondary index by sending instructions to multiple other nodes in the distributed system. Thus, multiple other nodes can receive instructions from the coordination node, respond to the instructions, and perform the configuration operation of the metadata of the corresponding global secondary index. After confirming that multiple other nodes have completed the configuration of the metadata of the global secondary index, the coordination node synchronizes the configuration of the metadata of the global secondary index on its own node. In this way, this solution can realize the online creation of the global secondary index in the distributed system based on the synchronous update (non-asynchronous update) of metadata, while ensuring the global consistency of metadata. And because the node that executes the online creation of the global secondary index in this solution is not a specific node, but any coordination node in the distributed system can execute it. In this way, neither the node will frequently increase the additional burden due to the fixed node to execute the online creation of the global secondary index, nor will it be necessary to introduce a third-party node / tool with high concurrent access load to coordinate metadata updates. In this way, the distributed system can effectively guarantee concurrent high performance under large-scale clusters during the online creation of global secondary indexes.
[0045] In a possible implementation, each of the multiple other nodes is further configured to return completion feedback information to the coordination node when completing metadata configuration of the global secondary index on its own node;
[0046] The coordination node is also used to receive completion feedback information, and when receiving completion feedback information returned by each of the multiple other nodes, determine that the coordination node meets the preset conditions. In this way, in a distributed system including the coordination node and multiple other nodes, when multiple other nodes in the distributed system receive instructions from the coordination node and respond to the instructions to complete the configuration operation of the metadata of the corresponding global secondary index, they can return an indication information to the coordination node, so that the coordination node can promptly confirm that the multiple other nodes have completed the metadata configuration.
[0047] In a possible implementation, the coordination node is also used to determine whether the coordination node meets the preset conditions after waiting for a preset processing time. In this way, in the online creation process of the global secondary index, when the coordination node notifies multiple other nodes to complete the metadata configuration, it can automatically assume that multiple other nodes have completed the corresponding metadata configuration after waiting for a certain period of time.
[0048] In a possible implementation, when the above configuration is used to generate metadata, the instructions sent by the above coordinating node to multiple other nodes in the distributed system may include a first instruction (such as the first instruction information sent by the coordinating node in step S702), and the first instruction is used to instruct the multiple other nodes to generate metadata for the global secondary index. The above distributed system also includes a client, wherein:
[0049] The client is used to send an index creation request, where the index creation request is used to instruct online creation of a global secondary index associated with a field on a data table;
[0050] A coordinating node, configured to receive an index creation request, and send a first instruction to a plurality of other nodes in response to the index creation request;
[0051] Each node among the multiple other nodes is used to receive the first instruction, and in response to the first instruction, create and initialize metadata of the global secondary index on its own node, and set the metadata version of the global secondary index to the first version;
[0052] The coordination node is also used to create and initialize the metadata of the global secondary index on the coordination node when the coordination node meets preset conditions, and set the metadata version of the global secondary index to the first version.
[0053] In this way, in a distributed system including a coordination node and multiple other nodes, when there is a coordination node that receives a global secondary index creation request from a client, the coordination node can be directly responsible for the entire online creation process of the global secondary index. At this time, the coordination node can begin to enter the metadata generation phase (initialization phase) of the global secondary index. That is, the coordination node guides multiple other nodes to perform the generation operation of the global secondary index by sending a first instruction to multiple other nodes in the distributed system, and when it is determined that multiple other nodes have completed the metadata generation of the global secondary index, it synchronously completes the metadata generation of the global secondary index on its own node. In this way, the coordination node that receives the global secondary index creation request is used to implement the metadata initialization of the non-asynchronous mechanism in the online creation process of the global secondary index, which not only ensures the global consistency of metadata, but also ensures the concurrent high performance under large-scale clusters.
[0054] Optionally, each of the multiple other nodes is further configured to return setting feedback information to the coordination node when completing the creation and initialization of the metadata of the global secondary index and the first version setting of the metadata version on the own node;
[0055] The coordination node is further configured to receive setting feedback information, and upon receiving setting feedback information returned by each of the multiple other nodes, determine that the coordination node meets a preset condition.
[0056] In a possible implementation, when the above configuration is used to update metadata, the instruction sent by the above coordinating node to multiple other nodes in the distributed system may include a second instruction (such as the fifth instruction information sent by the coordinating node in the specific implementation), and the second instruction is used to instruct multiple other nodes to update the metadata of the global secondary index. Wherein:
[0057] The coordinating node is used to send a second instruction to the plurality of other nodes when the coordinating node and the plurality of other nodes have completed the first version setting of the metadata version in the metadata of the global secondary index;
[0058] Each node among the plurality of other nodes is configured to receive the second instruction, and in response to the second instruction, update the metadata version on the node itself from the first version to the second version;
[0059] The coordination node is also used to update the metadata version from the first version to the second version on the coordination node when the coordination node meets a preset condition.
[0060] In this way, in a distributed system including a coordination node and multiple other nodes, the coordination node can guide multiple other nodes to perform the update operation of the global secondary index by sending a second instruction to multiple other nodes in the distributed system during the metadata update phase of the global secondary index. And when it is determined that multiple other nodes have completed the metadata update of the global secondary index, the metadata update of the global secondary index is synchronously completed on its own node. In this way, the coordination node that receives the global secondary index creation request is used to implement the metadata update of the non-asynchronous mechanism during the online creation process of the global secondary index, which not only ensures the global consistency of metadata, but also ensures the concurrent high performance under large-scale clusters.
[0061] Optionally, each of the multiple other nodes is further configured to return update feedback information to the coordination node when completing the second version update of the metadata version of the global secondary index on its own node;
[0062] The coordination node is further configured to receive update feedback information, and upon receiving update feedback information returned by each of the multiple other nodes, determine that the coordination node meets a preset condition.
[0063] In a possible implementation, when the above configuration is used to update metadata, and the global secondary index is available after the update, the instruction sent by the above coordinating node to multiple other nodes in the distributed system may include a second instruction (such as the third instruction information sent by the coordinating node in step S707), and the second instruction is used to instruct the multiple other nodes to update the metadata of the global secondary index, wherein:
[0064] The coordinating node is used to fill the relevant data in the data table into the global secondary index when the coordinating node and the plurality of other nodes complete the first version setting of the metadata version in the metadata of the global secondary index, and send a second instruction to the plurality of other nodes when the data filling of the global secondary index is completed;
[0065] Each node among the plurality of other nodes is configured to receive the second instruction, and in response to the second instruction, update the metadata version on the node itself from the first version to the second version;
[0066] The coordination node is also used to update the metadata version from the first version to the second version on the coordination node when the coordination node meets a preset condition.
[0067] Optionally, each of the multiple other nodes is further configured to return update feedback information to the coordination node when completing the second version update of the metadata version of the global secondary index on its own node;
[0068] The coordination node is also used to receive update feedback information, and when receiving update feedback information returned by each of the multiple other nodes, it determines that the coordination node meets the preset conditions. In this way, in a distributed system including a coordination node and multiple other nodes, after completing the data filling of the global secondary index and entering the final metadata update stage of the global secondary index, the coordination node can guide multiple other nodes to perform the final update operation of the global secondary index by sending a second instruction to multiple other nodes in the distributed system. And when it is determined that multiple other nodes have completed the metadata update of the global secondary index, the final update of the metadata of the global secondary index is synchronously completed on its own node. In this way, the coordination node that receives the global secondary index creation request is used to implement the final update of the metadata of the non-asynchronous mechanism in the online creation process of the global secondary index, which not only ensures the global consistency of the metadata, but also ensures the concurrent high performance under large-scale clusters.
[0069] In a possible implementation, the coordinating node is also used to wait for all transactions of the data tables on the coordinating node and multiple other nodes to end after the coordinating node and multiple other nodes have completed the first version setting of the metadata version in the metadata of the global secondary index. Then the coordinating node executes the aforementioned subsequent process. In this way, in a distributed system including a coordinating node and multiple other nodes, the coordinating node can follow the user DML transaction priority principle and complete the non-asynchronous update of metadata. This not only ensures the consistency of the base table and index data under the metadata non-asynchronous update mechanism, but also does not hinder the normal execution of user DML transactions, thereby ensuring high availability during the creation process.
[0070] In a possible implementation, the preset condition includes a first preset condition and a second preset condition. When the configuration is used to generate and update metadata, the instructions sent by the coordination node to multiple other nodes in the distributed system may include a first instruction and a second instruction. The first instruction is used to instruct the multiple other nodes to generate metadata for the global secondary index, and the second instruction is used to instruct the multiple other nodes to update the metadata for the global secondary index. The distributed system also includes a client, wherein:
[0071] The client is used to send an index creation request, where the index creation request is used to instruct online creation of a global secondary index associated with a field on a data table;
[0072] A coordinating node, configured to receive an index creation request, and send a first instruction to a plurality of other nodes in response to the index creation request;
[0073] Each node among the multiple other nodes is used to receive the first instruction, and in response to the first instruction, create and initialize metadata of the global secondary index on its own node, and set the metadata version of the global secondary index to the first version, where the first version is used to indicate that the global secondary index is writable but not readable;
[0074] The coordinating node is further used to create and initialize the metadata of the global secondary index on its own node when the coordinating node meets the first preset condition, and set the metadata version of the global secondary index to the first version;
[0075] The coordinating node is further used to fill the relevant data in the data table into the global secondary index after waiting for all transactions in the data table on the coordinating node and multiple other nodes to be completed, and send a second instruction to the multiple other nodes when the data filling of the global secondary index is completed;
[0076] Each of the multiple other nodes is further configured to receive a second instruction, and in response to the second instruction, update the metadata version on its own node from the first version to the second version, where the second version is used to indicate that the global secondary index is normally available;
[0077] The coordination node is further used to update the metadata version from the first version to the second version on its own node when the coordination node meets the second preset condition.
[0078] In this way, in a distributed system including a coordination node and multiple other nodes, the coordination node can not only use the aforementioned non-asynchronous mechanism to complete the metadata configuration during the online creation of the global secondary index, but the entire creation process only requires the state transition of two metadata versions. Therefore, the distributed system of this solution not only simplifies the metadata version transition process during the online creation of the global secondary index, but also simplifies the metadata version transition process while still ensuring the global consistency of metadata. It also follows the user DML transaction priority principle, and does not fix a certain node to execute the online creation of the global secondary index, ensuring high performance and high availability during the creation process.
[0079] Optionally, each of the multiple other nodes is further configured to return setting feedback information to the coordination node when completing the first version setting of the metadata version of the global secondary index on the own node;
[0080] The coordination node is further configured to receive setting feedback information, and upon receiving setting feedback information returned by each of the multiple other nodes, determine that the coordination node meets the first preset condition.
[0081] Optionally, each of the multiple other nodes is further configured to return update feedback information to the coordination node when completing the second version update of the metadata version of the global secondary index on its own node;
[0082] The coordination node is further configured to receive update feedback information, and upon receiving update feedback information returned by each of the multiple other nodes, determine that the coordination node meets the second preset condition.
[0083] In a possible implementation, the instruction sent by the above-mentioned coordinating node to multiple other nodes in the distributed system may include a third instruction (such as the sixth instruction information sent by the coordinating node in the specific implementation manner, the second instruction information sent by the coordinating node in step S704, etc.), and the third instruction is used to instruct multiple other nodes to wait for all transactions on the data table to end, wherein:
[0084] The coordinating node is further used to send a third instruction to a plurality of other nodes;
[0085] Each of the multiple other nodes is further configured to receive a third instruction, respond to the third instruction, and wait for all transactions of the data table on the own node to be completed;
[0086] The coordinating node is also used to wait for all transactions of the data table on the coordinating node to end when the coordinating node meets the specified conditions.
[0087] In this way, in a distributed system including a coordinating node and multiple other nodes, the coordinating node can also use the aforementioned non-asynchronous mechanism to complete the waiting for all DML transactions to be completed during the online creation of the global secondary index. That is, by sending a third instruction to multiple other nodes in the distributed system, the multiple other nodes are instructed to execute the waiting for all DML transactions. When it is determined that multiple other nodes have completed the waiting for all DML transactions, the waiting for all DML transactions is synchronously completed on its own node.
[0088] Optionally, each of the multiple other nodes is further configured to return waiting feedback information to the coordination node when all unfinished transactions on the data table are completed on its own node;
[0089] The coordination node is further configured to receive waiting feedback information, and upon receiving waiting feedback information returned by each of the multiple other nodes, determine that the coordination node meets the specified condition.
[0090] In a possible implementation, the instruction is a structured query language SQL instruction. Thus, in a distributed system including a coordinating node and multiple other nodes, the coordinating node instructs multiple other nodes to perform the configuration operation of the metadata of the global secondary index by sending SQL instructions to the multiple other nodes in the distributed system.
[0091] In a third aspect, an index creation device in a distributed system is provided, which is applied to a coordination node in the distributed system, and the distributed system also includes multiple other nodes. The device includes: a processing unit, which is used to notify the multiple other nodes to configure metadata of the global secondary index during the online creation process of the global secondary index, wherein the metadata includes a metadata version configured to update and / or generate the metadata;
[0092] The processing unit is further used to configure metadata of the global secondary index on the coordination node when the coordination node meets preset conditions.
[0093] In a possible implementation, the receiving unit is further configured to receive completion feedback information. The processing unit is further configured to: upon receiving completion feedback information returned by each of the multiple other nodes, determine that the coordination node meets a preset condition.
[0094] In a possible implementation manner, the processing unit is further configured to: after waiting for a preset processing time, determine whether the coordination node meets a preset condition.
[0095] In a possible implementation, the distributed system also includes a client. When the above configuration is used to generate metadata, the index creation device in the above distributed system may also include: a receiving unit, used to receive an index creation request from the client, the index creation request is used to indicate the online creation of a global secondary index associated with a field on a data table. The above processing unit is used to: in response to the index creation request, notify multiple other nodes to create and initialize the metadata of the global secondary index, and set the metadata version of the global secondary index to the first version. The above processing unit is also used to: when the coordination node meets the preset conditions, create and initialize the metadata of the global secondary index on the coordination node, and set the metadata version of the global secondary index to the first version.
[0096] In a possible implementation, the receiving unit is further configured to receive setting feedback information. The processing unit is further configured to: upon receiving setting feedback information returned by each of the multiple other nodes, determine that the coordinating node meets the preset condition. The setting feedback information returned by each node can be used to indicate that the creation and initialization of the metadata of the global secondary index on its node and the setting of the first version have been completed.
[0097] In a possible implementation, when the above configuration is used to update metadata, the processing unit is used to: when the coordination node and multiple other nodes complete the first version setting of the metadata version in the metadata of the global secondary index, notify multiple other nodes to update the metadata version from the first version to the second version. The processing unit is also used to: when the coordination node meets the preset conditions, update the metadata version from the first version to the second version on the coordination node.
[0098] In a possible implementation, the receiving unit is further used to receive update feedback information. The processing unit is further used to: upon receiving update feedback information returned by each of the multiple other nodes, determine that the coordination node meets a preset condition. The update feedback information returned by each node can be used to indicate that the second version update of the metadata version of the global secondary index on its node has been completed.
[0099] In a possible implementation, when the above configuration is used to update metadata, the processing unit is used to: when the coordination node and multiple other nodes have completed the first version setting of the metadata version in the metadata of the global secondary index, fill the relevant data in the data table into the global secondary index; when the data filling of the global secondary index is completed, notify multiple other nodes to update the metadata version from the first version to the second version. The processing unit is also used to: when the coordination node meets the preset conditions, update the metadata version from the first version to the second version on the coordination node.
[0100] In a possible implementation, the processing unit is further configured to: wait for all transactions of the data tables on the coordinating node and the other nodes to be completed.
[0101] In a possible implementation, the distributed system also includes a client, and the above-mentioned preset conditions include a first preset condition and a second preset condition. When the above-mentioned configuration is used to generate and update metadata, the index creation device in the above-mentioned distributed system may also include: a receiving unit, used to receive an index creation request from the client, and the index creation request is used to indicate the online creation of a global secondary index associated with a field on a data table. The above-mentioned processing unit is used to: in response to the index creation request, notify multiple other nodes to create and initialize the metadata of the global secondary index, and set the metadata version of the global secondary index to the first version, and the first version is used to indicate that the global secondary index is writable but not readable; when the coordination node meets the first preset condition, create and initialize the metadata of the global secondary index on the coordination node, and set the metadata version of the global secondary index to the first version. The above-mentioned processing unit is also used to: after waiting for all transactions of the data table on the coordination node and multiple other nodes to be completed, fill the relevant data in the data table into the global secondary index. The above-mentioned processing unit is also used to: when the data filling of the global secondary index is completed, notify multiple other nodes to update the metadata version from the first version to the second version, and the second version is used to indicate that the global secondary index is normally available; when the coordination node meets the second preset condition, update the metadata version from the first version to the second version on the coordination node.
[0102] In a possible implementation, the receiving unit is further configured to receive setting feedback information. The processing unit is further configured to: upon receiving setting feedback information returned by each of the multiple other nodes, determine that the coordinating node satisfies the first preset condition. The setting feedback information returned by each node can be used to indicate that the creation and initialization of the metadata of the global secondary index on its node and the setting of the first version have been completed.
[0103] In a possible implementation, the receiving unit is further used to receive update feedback information. The processing unit is further used to: upon receiving update feedback information returned by each of the multiple other nodes, determine that the coordinating node meets the second preset condition. The update feedback information returned by each node can be used to indicate that the second version update of the metadata version of the global secondary index on its node has been completed.
[0104] In a possible implementation, the processing unit is further used to: notify multiple other nodes to wait for all transactions on the data table to be completed; and when the coordinating node meets the specified conditions, wait for all transactions on the data table on its own node to be completed.
[0105] In a possible implementation, the receiving unit is further configured to receive waiting feedback information. The processing unit is further configured to: upon receiving waiting feedback information returned by each of the multiple other nodes, determine whether the coordination node meets the specified condition. The waiting feedback information returned by each node can be used to indicate that all unfinished transactions on the data table have been completed on its node.
[0106] In a possible implementation, the processing unit is used to send a structured query language SQL instruction to multiple other nodes, where the SQL instruction is used to instruct the multiple other nodes to configure metadata of the global secondary index.
[0107] In a fourth aspect, a coordination node in a distributed system is provided, the coordination node comprising one or more processors and one or more memories, the one or more memories storing at least one computer program, the at least one computer program being loaded by the one or more processors and executing the index creation method in a distributed system in the first aspect and any possible design method thereof.
[0108] In a fifth aspect, a chip system is provided, which includes one or more interface circuits and a processor; the interface circuit and the processor are interconnected through lines; the interface circuit is used to receive signals and send signals to the processor, and the signals include instructions; when the processor executes the instructions, the chip system executes the index creation method in a distributed system in the above-mentioned first aspect and any possible design method thereof.
[0109] In a sixth aspect, a computer-readable storage medium is provided, comprising computer instructions, which, when executed on a computer, enable the computer to execute the index creation method in a distributed system in the first aspect and any possible design thereof.
[0110] It can be understood that the beneficial effects that can be achieved by the device of the third aspect, the coordination node of the fourth aspect, the chip system of the fifth aspect, and the computer storage medium of the sixth aspect provided above can be referred to the beneficial effects in the first aspect and any possible implementation thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0111] Figure 1 A system diagram of an index creation method provided for related technologies Figure 1 ;
[0112] Figure 2 A system diagram of an index creation method provided for related technologies Figure 2 ;
[0113] Figure 3 A system diagram of an index creation method provided for related technologies Figure 3 ;
[0114] Figure 4 A system diagram of an index creation method provided for related technologies Figure 4 ;
[0115] Figure 5 A schematic diagram of the system architecture of a method for creating an index in a distributed system provided in an embodiment of the present application;
[0116] Figure 6 A schematic diagram of the software architecture flow of an index creation method in a distributed system provided in an embodiment of the present application;
[0117] Figure 7 A schematic diagram of a flow chart of a method for creating an index in a distributed system provided in an embodiment of the present application;
[0118] Figure 8 A timing diagram of an index creation method in a distributed system provided in an embodiment of the present application;
[0119] Fig. 9 A schematic diagram of data distribution in a distributed system provided in an embodiment of the present application;
[0120] Fig.10 Another data distribution diagram provided for an embodiment of the present application;
[0121] Fig.11 A schematic diagram of a flow chart of a method for synchronously deleting tuples in a distributed system provided in an embodiment of the present application;
[0122] Fig.12 A schematic diagram of a flow chart of a method for inserting tuples after synchronously deleting tuples in a distributed system provided in an embodiment of the present application;
[0123] Fig.13 A schematic diagram of data partitioning in a distributed system provided in an embodiment of the present application;
[0124] Fig.14 A schematic diagram of data partitioning in another distributed system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0125] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. In the following, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. It should be understood that in the present application, "at least one" refers to one or more, and "multiple" refers to two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural.
[0126] For the purpose of reference and clarity, the technical terms, abbreviations or acronyms used below are summarized and explained as follows:
[0127] Index: A data structure that sorts the values of one or more columns in a data table to assist in quickly querying and updating data in the data table. The function of an index is equivalent to the catalog of a book, and you can quickly find the required content based on the page numbers in the catalog.
[0128] Data manipulation language DML: a language used to implement operations on data in the database (such as query, insert, update, delete, etc.).
[0129] Distribution key: In a distributed database, a column (or combination of columns) that is used to determine the database partition where a specific row of data is stored.
[0130] Index Key: A column (or combination of columns) that identifies an index item.
[0131] Base Table: also known as basic table, data table, metadata permanently stored in the database, distinguished from indexes, views, etc.
[0132] Snapshot: A snapshot of a database is a read-only static view that records the data information in the database at a certain point in time.
[0133] Metadata (Schema): some data that describes the database itself, including metadata version, database name, database character set, table name, table size, number of record rows in the table, table character set, table fields, table indexes, table description, field type, field precision, field description, etc.
[0134] Memtable: A data structure in the log structured merge tree (LSM) storage structure used to store the latest written data, generally stored in memory. When the written data accumulates to a certain threshold, the background merge process merges it into the sorted string table (SSTable).
[0135] Sorted string table (SSTable): A data structure used to store historical data in the LSM storage structure, generally stored on disk.
[0136] A global secondary index (GSI), also known as a global index, is a type of index. An index is a sorted data structure in a database system that is used to quickly query and update data in a database base table. A global secondary index is a global index that is effective on data nodes in a distributed database. An index key is a column (or combination of columns) that identifies an index item in a global secondary index.
[0137] A coordinator node (CN) is a node that performs data scheduling. The coordinator node can manage data nodes that establish communication connections with the coordinator node and perform data scheduling between data nodes.
[0138] A data node (DN) is a node used to process and store data. A data node can receive data scheduling information from a coordination node and send or receive data or perform data processing and storage based on the received data scheduling information.
[0139] Currently, in distributed databases, the creation of a global secondary index GSI usually takes hours or even days when the amount of data is large. To avoid blocking the DML transaction processing of user services, the creation of a global secondary index GSI must be done online, that is, the DML transaction processing of user services can be run in parallel during the creation process without blocking each other.
[0140] In order to realize the online creation of distributed global secondary indexes, a multi-version metadata asynchronous update algorithm is usually adopted at present. That is, during the creation process, at the same time point, a node is allowed to have two and at most two valid metadata versions. The index creation is performed by a specific node, and after the specific node updates its own metadata version, other nodes update the metadata version asynchronously accordingly. In this way, the online creation of distributed global secondary indexes can be realized on the basis of ensuring data consistency. Among them, data consistency in this scheme means that after the distributed database completes the creation of the index on the base table, the index is consistent with the data in the base table in the corresponding column, avoiding different processing results for the same task request index and base table feedback.
[0141] To ensure that a node has at most two valid metadata versions, as a solution, the lease mechanism can be used to implement asynchronous metadata updates. That is, after a specific node used to create an index updates its metadata version, it waits for other nodes to asynchronously update their metadata versions within a lease period. If the node fails to update, it is considered an abnormal exit.
[0142] For example, Figure 1 As shown in the figure, from the beginning to the completion of index creation, the metadata transitions through multiple version states in sequence, namely: initial (absent), deletable but not readable or writable (delete only), writable but not readable (write only (data reorganization)), and available (public). Among them, the version absent means that the index has not been initialized and is completely invisible. The version delete only means that when a certain data in the base table is deleted, if this data exists in the index, it is deleted in the index. The version write only means that when a certain data in the base table is deleted, inserted, or updated, the corresponding operation is also performed on this data in the index. Data reorganization indicates the process of filling the index with base table data. The version public means that the creation is completed and the index can be used to accelerate queries.
[0143] like Figure 1 As shown, Figure 1 A solution for implementing asynchronous metadata updates using a lease mechanism is shown.
[0144] First, a GSI creation command is forwarded to a specific node to instruct the specific node to perform index creation.
[0145] Then at time T0, the specific node used to create the index creates and initializes the index-related metadata, sets the metadata version absent, and starts waiting for a lease time. Other nodes pull the metadata version absent and update themselves within a lease time.
[0146] Then at time T1, a lease time ends, and the specific node updates to the metadata version delete only and starts waiting for a lease time. Other nodes start pulling the metadata version delete only to update themselves.
[0147] Then at time T2, a lease time ends, and the specific node updates to the metadata version write-only, and starts waiting for a lease time. Other nodes start to pull the metadata version write-only and update themselves.
[0148] Then at time T3, a lease time ends, and the specific node obtains the current snapshot and fills the index with the base table data under the snapshot.
[0149] Finally, at time T4, the data filling index is completed, the specific node is updated to the public metadata version, and other nodes begin to pull the public metadata version, and the index creation is completed.
[0150] It can be seen that during the entire index creation process, metadata is updated asynchronously, that is, the metadata version V is updated on the specific node used to perform index creation. n After that, other nodes asynchronously refresh to the latest metadata version. After confirming that all currently active nodes have updated the metadata version V n After that, the specific node can be updated to the next metadata version V n+1 The entire index creation process follows the principle of adjacent metadata version compatibility, that is, at the same time point during the creation process, a node is allowed to have two and at most two adjacent valid metadata versions. This ensures that there will be no active transactions holding non-adjacent metadata versions in the distributed database at the same time, ensuring data consistency between the base table and the index after the index is created.
[0151] However, for Figure 1 The scheme shown in FIG. 1 uses a lease mechanism to implement asynchronous metadata updates, and is used by a specific node that performs index creation to update its own metadata version V n After that, it will automatically update to metadata version V after waiting for a lease period (usually several minutes). n+1 This requires other nodes to actively pull metadata version V within a lease time. n If the node fails to pull, the node will automatically exit the operation, the transaction being processed will be forced to stop and roll back, and the node processing will be handed over to the background service to try to pull it up again. In order to realize GSI online creation, the synchronization DML transaction during the creation process cannot be longer than a lease time, otherwise the node will terminate the transaction and roll back. This ensures that the metadata version V is updated on a specific node n+1 When there is no metadata version V n-1 The transaction is still executing.
[0152] It can be seen from this that if the above lease mechanism is used to implement the asynchronous metadata update solution, the index creation will take at least three leases, even when the amount of data is relatively small. Secondly, in order to ensure the compatibility of adjacent metadata versions, this solution also limits the maximum execution time of DML transactions. Furthermore, if the node cannot be updated to the latest metadata version within a lease time, it must exit the operation, and the DML transaction being processed must be forced to terminate and roll back, causing user business to be affected. Therefore, although Figure 1 The solution shown in the figure that uses the lease mechanism to implement asynchronous metadata updates can realize online creation of GSI and also ensure data consistency, but it also limits the minimum execution time of creation, limits the maximum execution time of DML transactions, and cannot guarantee high availability.
[0153] As another solution, you can also use third-party components / tools to implement asynchronous metadata updates. That is, after the specific node used to create the index updates the metadata version, it uploads the latest metadata version to the third-party component / tool. The third-party component / tool is responsible for synchronizing the latest metadata version to other nodes and then feeding it back to the specific node.
[0154] As an example, Figure 2 As shown, Figure 2 A solution for implementing asynchronous metadata updates using a placement driver (PD) is shown. From the start to the completion of index creation, metadata still needs to follow the adjacent metadata version compatibility principle and needs to transition to multiple version states in sequence, namely: absent, delete only, writeonly, data reorganization, and public.
[0155] like Figure 2 As shown, first, the GSI creation command is forwarded to a specific node to instruct the specific node to perform index creation. Then the specific node used to perform index creation waits for the currently active old transaction to complete by obtaining metadata. After the wait is over, the index-related metadata will be created and initialized. The metadata version is updated to absent and uploaded to PD (third-party tool). PD pushes the metadata version to other nodes. Each node waits for the currently active old transaction to complete and updates the metadata version from PD. After completion, each node feeds back to PD, and PD feeds back to the specific node. The specific node updates to the metadata version delete only.
[0156] Repeat the above steps until the specific node is updated to the metadata version data reorganization. The specific node waits for the current active old transaction to complete and then obtains the current snapshot, and fills the index with the base table data under the snapshot.
[0157] Then the data filling index is completed, and the specific node uploads the metadata version data reorganization to PD. PD is pushed to other nodes, and each node waits for the currently active old transaction to complete, and updates the metadata version data reorganization from PD. After each node is completed, it feedbacks to PD. After receiving the feedback from PD, the specific node updates to the metadata version public. Index creation is completed. The specific node uploads the metadata version public to PD, and PD pushes it to other nodes.
[0158] It can be seen that for Figure 2 The solution shown in FIG. 1 is to use a third-party tool PD to coordinate the asynchronous update of metadata, and to update the metadata version V of the specific node that performs index creation. n After that, you need to change your metadata version V n Status is uploaded to PD. PD pushes version V n After the PD is sent to other nodes and the node is confirmed to be successfully updated, it is fed back to the specific node. The specific node can enter the metadata version V after receiving the PD feedback. n+1 In order to realize the online creation of GSI, the scheme follows the principle of user DML transaction priority, that is, specific nodes are updated to enter version V n After that, you need to wait for the transaction to complete by acquiring the metadata lock (metadata version <= V n-1 The transaction ends), and then the specific node can enter version V n+1 .
[0159] However, for PD (one active and two standby nodes), if Figure 2 As shown, PD itself is responsible for the metadata management of the distributed system and has undertaken many high-load and high-network communication tasks, such as global metadata management, which is used to store metadata information (including data distribution and cluster topology, etc.); distributed transaction management, which is used to assign transaction sequence numbers to distributed transactions; data distribution management, which sends data scheduling commands to specific nodes based on the real-time data distribution of each storage node.
[0160] From this, it can be seen that if the above-mentioned third-party tool PD is used to coordinate the asynchronous update of metadata, although the online creation of GSI can be realized and data consistency can be guaranteed, all nodes in the distributed system need to frequently and stably connect to the PD master node, which introduces the additional burden of online index creation to PD, resulting in its concurrent high performance in a large-scale cluster environment being affected, and the concurrent high performance during the creation process cannot be guaranteed.
[0161] As another example, Figure 3 As shown, Figure 3 A scheme for implementing asynchronous metadata updates using a global metadata service (GMS) is shown. From the beginning to the completion of index creation, metadata still needs to follow the principle of compatibility between adjacent metadata versions and needs to transition to multiple version states in sequence, namely: absent, delete only, write only, data reorganization, and public.
[0162] like Figure 3 As shown, first, the GSI creation command is forwarded to a specific node to instruct the specific node to execute index creation. Then the specific node used to execute index creation creates and initializes index-related metadata, updates the metadata version to absent and uploads it to GMS (a third-party tool), and waits for the DML transaction holding the old version to complete. GMS pushes the metadata version absent to other nodes. Each node waits for the currently active old transaction to complete and updates the metadata version from GMS. After each node is completed, it will feedback to GMS, and GMS will feedback to the specific node after confirming that other nodes have completed the update. The specific node is updated to enter the metadata version delete only.
[0163] Repeat the above steps until the specific node is updated to the metadata version data reorganization. The specific node obtains the current snapshot and fills the index with the base table data under the snapshot.
[0164] After the data is filled in the index, the specific node uploads the metadata version to GMS and waits for the DML transaction holding the old version to complete. GMS pushes the metadata version to other nodes. Each node waits for the currently active old transaction to complete and updates the metadata version data reorganization from GMS. After completion, each node feedbacks to GMS. After receiving feedback from GMS, the specific node updates to the metadata version public. Index creation is completed.
[0165] It can be seen that for Figure 3The solution shown in FIG. 1 is to use a third-party tool GMS to coordinate the asynchronous update of metadata, and to update its own metadata version V for a specific node that performs index creation. n After that, you also need to change your own metadata version V n Status is uploaded to GMS. GMS push version V n After the GMS feedback is sent to other nodes and the node is confirmed to be successfully updated, it is fed back to the specific node. The specific node can enter the metadata version V after receiving the GMS feedback. n+1 In order to realize the online creation of GSI, this solution also follows the principle of user DML transaction priority, that is, specific nodes are updated to enter version V n After that, you need to wait for the transaction to complete by acquiring the metadata lock (metadata version <= V n-1 The transaction ends), and then the specific node can enter version V n+1 .
[0166] However, for GMS (which also has one active and two standby nodes), Figure 3 As shown in the figure, GMS itself is responsible for the metadata management of the distributed system and has undertaken many high-load and high-network communication tasks, such as global metadata management, which is used to store global metadata information; distributed global clock management, which is used to provide global timing services; security information management, which is used to maintain security information such as accounts and permissions; data distribution management, which sends scheduling data redistribution commands to nodes; resource scheduling, adding / deleting nodes, etc.
[0167] From this, it can be seen that if the above-mentioned third-party tool GMS is used to coordinate the asynchronous update of metadata, although the online creation of GSI can be realized and data consistency can be guaranteed, it also requires all nodes in the distributed system to frequently and stably connect to the GMS master node, which introduces the additional burden of online index creation to GMS, resulting in its concurrent high performance in a large-scale cluster environment being affected, and the concurrent high performance during the creation process cannot be guaranteed.
[0168] As another example, Figure 4 As shown, Figure 4 A scheme for implementing asynchronous metadata updates using a central node Root Server is shown. From the beginning to the completion of index creation, metadata still needs to follow the principle of compatibility between adjacent metadata versions and needs to transition to multiple version states in sequence, namely: absent, write only (data reorganization), and public. It can be understood that in this type of distributed database, the logstructured merge tree (LSM) data storage architecture can be used to simplify metadata version transition while still ensuring data consistency.
[0169] like Figure 4 As shown, first, the GSI creation command is forwarded to the central node Root Server (third-party node), and the Root Server executes the index creation. Then the Root Server initializes the index-related metadata and sets the metadata version to absent.
[0170] Then, the root server updates the metadata version to write only, waits for the DML transaction holding the old version to complete, and asynchronously refreshes it to other nodes.
[0171] Next, the Root Server waits until the process is finished, obtains the current snapshot, and fills the index with the base table data under the snapshot.
[0172] Finally, the population is completed, and if necessary, the consistency check between the base table and the index is performed. After the population and verification are completed, the root server confirms that other nodes have updated the metadata version and has waited for the DML transaction holding the old version to complete. The root server updates the metadata version to public and asynchronously refreshes it to other nodes, and the index creation is completed.
[0173] It can be seen that for Figure 4 The solution shown in FIG. 1 uses a third-party Root Server node to coordinate the asynchronous update of metadata. The index creation command needs to be delivered to the Root Server node, and during the creation process, the Root Server node first updates its own metadata version V n After that, it notifies other nodes to refresh asynchronously. At the same time, other nodes can also check and refresh the version from the Root Server node through the heartbeat packet. At the same time, in order to realize the online creation of GSI, this solution also follows the principle of user DML transaction priority, that is, the Root Server node updates to version V. n After that, you need to wait for the transaction to complete by acquiring the metadata lock (metadata version <= V n-1 The transaction is completed), and then the Root Server node can enter version V n+1 .
[0174] However, the Root Server node (one primary and multiple backup nodes) is itself the master control service node of the distributed system, and has undertaken many high-load and high-network communication tasks, such as metadata management, which can schedule and manage data definition language (DDL) statements; data distribution management, which can determine data distribution location information; resource balancing management, which can manage the migration of resources between nodes; resource scheduling management, which can add or delete nodes, etc.
[0175] From this, it can be seen that if the above-mentioned third-party node Root Server node is used to coordinate the asynchronous update of metadata, although the online creation of GSI can be realized and data consistency can be guaranteed, it also requires all nodes in the distributed system to frequently and stably connect to the Root Server master node, which introduces the additional burden of online index creation to the Root Server, causing its concurrent high performance in a large-scale cluster environment to be affected, and the concurrent high performance during the creation process cannot be guaranteed.
[0176] In summary, if the lease mechanism is used to implement the online creation of the global secondary index GSI, the node that cannot successfully update the metadata within a lease time will exit the node cluster processing, and the ongoing user DML transaction of the node will also be forced to terminate and roll back, so high availability cannot be guaranteed. If a third-party component / tool is used to implement the online creation of the global secondary index GSI, it is necessary to have the flexibility to connect all nodes in the cluster, so the global metadata management module or central node is usually used as a third-party component / tool. However, the global metadata management module or central node itself has undertaken many high-load and high-network communication tasks, such as data distribution management and distributed transaction management. The introduction of the additional burden of online index creation will affect its concurrent high performance under a large cluster. Therefore, the current solution for online creation of the global secondary index GSI is difficult to guarantee high availability or concurrent high performance.
[0177] In order to solve the above problems, an embodiment of the present application provides an index creation method in a distributed system, which can realize the online creation of a global secondary index GSI based on a non-asynchronous update of metadata, and can ensure high availability or concurrent high performance during the creation process while ensuring data consistency.
[0178] It can be understood that the index creation method in the distributed system provided in the embodiment of the present application is applicable to various distributed system applications such as distributed domain name system (DNS), distributed router system, distributed database, distributed file system, distributed computing, distributed search engine, distributed cache, etc., and the embodiment of the present application does not limit this.
[0179] See also Figure 5 , Figure 5 A distributed system architecture provided by an embodiment of the present application is shown. The distributed system may include a user client, N coordinating nodes ((coordinating node, CN) or (coordinator)) and M data nodes (data node, DN), where N and M are positive integers. The client and the coordinating node can communicate with each other, and the coordinating node and each data node can communicate with each other.
[0180] The client can be used to receive instructions input by the user and send the instructions to the coordination node. For example, the instructions input by the user in the client may include storage instructions, modification instructions, insert, update, delete (insert / update / delete, IUD) instructions, etc. In an embodiment of the present application, the distributed system may include at least one client, and the instructions input by the user in the client may be instructions for creating a global secondary index GSI. Among them, the client can receive the creation GSI instruction input by the user and send the creation GSI instruction to the coordination node.
[0181] In the embodiment of the present application, when a user sends a GSI creation instruction through a client, there is a coordination node (such as coordination node 1) in the distributed system that can receive the GSI creation instruction. The coordination node that receives the GSI creation instruction can be responsible for the entire GSI online creation process and execute the index creation method provided in the embodiment of the present application.
[0182] In an embodiment of the present application, during the online creation process of the GSI of the distributed system, the IUD operation instructions input by the user on the client can also be synchronously processed by the distributed system. For example, in the above-mentioned distributed system, while the user sends an instruction to create a global secondary index GSI on a base table through the client, he can also send instructions such as deletion, modification, and update on this base table. The two instructions will be processed in parallel by the distributed system. That is, during the online creation process of the GSI, when inserting, updating, and deleting operations are performed on the data in the base table, the global secondary index GSI of the base table will be synchronously updated accordingly, thereby ensuring the consistency of the base table data and the global secondary index GSI data after the online creation of the GSI is completed.
[0183] It can be understood that when a user sends an IUD operation instruction through a client, a distributed system will also have a coordination node (such as coordination node 2) that can receive the IUD operation instruction. The coordination node that receives the IUD operation instruction can be responsible for the entire execution process of the IUD operation and perform the IUD operation on the data in the base table. Optionally, coordination node 1 and coordination node 2 can be the same or different. Among them, the coordination node can be used to receive user requests from the client, parse the user request and perform corresponding operations, or send the indication information to the data node so that the data node can perform corresponding operations based on the indication information. Optionally, the coordination node can also receive data obtained by the data node based on the indication information, and return the data to the client. In an embodiment of the present application, when the user request is to create a GSI, the coordination node can issue a creation command to other nodes based on the request. The other nodes may include all data nodes in the distributed system, and may also include other coordination nodes in the distributed system.
[0184] As an example, when the user requests to store data, the coordination node can store the data in the data node based on the request. The data may include multiple sets of base table data, where the base table is a basic table (also called a data table) in the database. For any set of base table data, the base table data may include a distribution key, and the coordination node may store the base table data on the data node corresponding to the distribution key based on the distribution key corresponding to the base table data.
[0185] In addition, a column in the base table data can also be indexed, that is, each set of base table data can also correspond to a set of index data. For any set of index data, the index data can also correspond to a distribution key of the index data, and the coordination node can store the index data on the data node corresponding to the distribution key based on the distribution key corresponding to the index data.
[0186] In the embodiment of the present application, the index distributed on different data nodes from the base table can be called a global secondary index GSI. Correspondingly, the aforementioned index data can also be called global secondary index GSI data. For any set of GSI data, it can also correspond to a distribution key of GSI data. The coordination node can store the GSI data on the data node corresponding to the distribution key based on the distribution key corresponding to the GSI data.
[0187] For example, a distributed system may include three data nodes: data node 1, data node 2, and data node 3, wherein data node 1 may store base table data 1 and GSI data 1, data node 2 may store base table data 2 and GSI data 2, and data node 3 may store base table data 3 and GSI data 3.
[0188] Among them, each group of base table data and the GSI data corresponding to the base table data can be distributed in the same data node or in different data nodes. The present application does not limit the number of data nodes and the storage method of data in the present application. In practical applications, the base table data stored in any data node can be one group, multiple groups or zero groups, and the GSI data stored in any data node can also be one group, multiple groups or zero groups.
[0189] There is no requirement for the distribution of base table data and GSI data on data nodes. The distribution modes that can be selected include hash distribution, range distribution, list distribution, etc. As an example, for hash-distributed data, the data node corresponding to the data can be determined by calculating the hash value of the data. For range-distributed data, the data node corresponding to the data can be determined directly based on the range of the data. For list-distributed data, the data node corresponding to the data can be determined directly based on the list mapping value of the data.
[0190] Optionally, for any set of base table data, the base table data may also correspond to a partition key. After the coordination node determines the data node corresponding to the base table data, it may also store the base table data in the storage unit corresponding to the partition key based on the partition key corresponding to the base table data. Similarly, the partitioning methods of the base table data may also include multiple methods, such as hash, range, and list.
[0191] As an example, for hash partitioned data, the storage unit corresponding to the data can be determined by calculating the hash value of the data. For range-distributed base table data, the storage unit corresponding to the data can be directly determined based on the range of the data. For list-distributed base table data, the storage unit corresponding to the data can be directly determined based on the list mapping value of the data.
[0192] The coordination node may also send a mapping relationship of the base table data to each data node, wherein the mapping relationship is used to indicate a distribution logic between the base table data and the data nodes.
[0193] As an example, for base table data of hash distribution, the mapping relationship of the base table data may include the mapping relationship between each hash value and the data node corresponding to each hash value. For base table data of range distribution, the mapping relationship of the base table data may include the mapping relationship between each range and the data node corresponding to each range. For base table data of list distribution, the mapping relationship of the base table data may include the mapping relationship between each list mapping value and the data node corresponding to each list mapping value.
[0194] In the embodiment of the present application, the distribution mode and partition mode of the base table data are independent, and the distribution mode and partition mode can be used in combination. The base table data and GSI data in the embodiment of the present application are briefly introduced below.
[0195] Among them, the base table includes at least one column of data, and the at least one column of data can be divided into at least one row of data, that is, the base table includes at least one row × at least one column of data, such as 3 rows × 5 columns. In some embodiments of the present application, the data located in the same column in the base table belong to the same attribute, and the data located in the same row in the base table belong to the same tuple. The same tuple can be stored in the same storage location. At least one column of data in the base table can be used as the distribution key of the base table, and the distribution key of the base table is used to determine the storage location of the data in the base table. Optionally, there may also be at least one column of data used as a primary key in the base table. The distribution key and primary key of the base table may be the same or different. The distribution key and primary key of the base table can be data of a set column in the base table, or can be data determined according to user instructions.
[0196] In an embodiment of the present application, the global secondary index GSI of the base table includes data of some columns in the base table and location information corresponding to the data in the base table. The data of the some columns can be selected and set by the user from the column data of the base table, and the location information corresponding to the data is used to indicate the location of the corresponding data in the base table. Optionally, the location information includes the node where the data is located and the storage location within the node. Optionally, the global secondary index of the base table may also include version information (or transaction information) corresponding to the data in the base table, and the version information corresponding to the data is used to determine whether the corresponding data is valid. In some embodiments of the present application, data in the same column in the global secondary index belongs to the same attribute, and data in the same row belongs to the same tuple. The same tuple can be stored in the same position.
[0197] In some embodiments, at least one column of data in the global secondary index GSI can be used as a distribution key of the global secondary index, and the distribution key of the global secondary index GSI is used to determine the storage location of the data in the global secondary index GSI. The distribution key distribution mode can be hash distribution, list distribution, range distribution, etc.
[0198] In some embodiments, the global secondary index GSI may include index keys, additional keys (also referred to as additional columns / hidden columns / covered columns / included columns), etc. Among them, the index key is at least one column of data in the global secondary index GSI, which can be used to query specific data, thereby speeding up the query. The hidden column contains at least one column of data in the global secondary index GSI that is not visible to the user. When the user instructs to display the global secondary index GSI, the data of the global secondary index GSI displayed to the user does not include the hidden column data of the global secondary index GSI. The distribution key and index key of the global secondary index can be the same or different. The distribution key and index key of the global secondary index can be the data of the set column, or can be data determined according to the user's instructions.
[0199] In an embodiment of the present application, the coordination node and the data node can save the metadata of the base table and the global secondary index. The metadata shows the status of the base table or the global secondary index on the current node. Optionally, the metadata includes but is not limited to the description information of the database object, such as type, attribute, name, metadata version, etc.
[0200] In some embodiments, the instruction input by the user at the client may also be a query instruction. Upon receiving the query instruction input by the user, the client may send the query instruction to the coordination node, so that the coordination node may send indication information to the data node based on the query instruction, and the indication information may include query conditions and query methods. Among them, the data node may be used to store data, receive indication information from the coordination node, and perform corresponding operations based on the query conditions in the indication information. The query method may be understood as whether to use GSI to query data.
[0201] In an embodiment of the present application, the data node can query from the stored base table data based on the query condition, and can also query from the stored GSI data based on the query condition. Among them, when the query condition is a query condition based on the distribution key of the base table, the data node can quickly query the desired data from the stored base table data. When the query condition is a query condition based on other columns of the non-distribution key of the base table, if a global secondary index GSI based on other columns of the base table is created in the distributed system, the data node can also quickly query the desired data from the stored GSI data. In an embodiment of the present application, the coordination node can be a server with a control function. The coordination node and the data node can be independent servers, or they can be different virtual machines belonging to the same server or multiple servers. Optionally, the coordination node can also be a controller, or a chip applied to the controller.
[0202] See also Figure 6 , Figure 6 An index creation method based on the above-mentioned distributed system provided by an embodiment of the present application is shown. Among them, each node in the distributed system may include a parsing module, an optimization module and an execution module. The user can input a create global secondary index GSI statement on the coordination node through the client to trigger the creation process of the global secondary index GSI. After the user inputs the create GSI statement, the parsing module and the optimization module in the coordination node parse and optimize the create GSI statement respectively, and convert the create GSI statement into a data structure that can be recognized by the execution module, such as an execution plan. The execution module is used to implement the execution of the plan, such as sending the create command to other nodes.
[0203] In the above distributed system, a user can log in to the client to connect to the above distributed system. Figure 6As shown, after the user inputs the online creation of the global secondary index GSI statement through the client, there is a coordination node 1 in the distributed system that receives the online creation of the global secondary index GSI statement. At this time, the coordination node can be used as a node for executing the creation of the GSI index, and is responsible for the entire process of online creation of the GSI. After the online creation of the GSI statement is processed by the parsing and optimization module, it enters the execution module and can issue a creation command to other nodes to command other nodes to create and initialize the GSI metadata, and wait for all nodes (including itself) to complete the creation and initialization of the GSI metadata.
[0204] Other nodes can be other coordination nodes and data nodes, such as Figure 6 As shown, the coordination node 1 can send a creation command to the coordination node 2, the data node 1 and the data node 2. And wait for the coordination node 2, the data node 1 and the data node 2 to complete the creation and initialization of the GSI metadata.
[0205] After each node has executed GSI metadata creation and initialization through its own parsing module, optimization module, and execution module, it will feedback to coordination node 1. After coordination node 1 receives feedback from all other nodes, it issues a command to wait for the current active transaction to complete, and waits for all nodes (including itself) to complete the waiting for the current active transaction to complete. After each node has executed the waiting for the current active transaction through its own parsing module, optimization module, and execution module, it will feedback to coordination node 1. After coordination node 1 receives feedback from all other nodes, it starts to organize the base table data to fill in the global secondary index GSI.
[0206] In an embodiment of the present application, the coordination node 1 can fill data into the global secondary index by sending a structured query language (SQL) statement, and the parsing module and the optimization module can parse and optimize the instructions of the SQL statement and send it to the execution module. The execution module can query and obtain the data required to create the global secondary index from the data node according to the instruction. The obtained data is then stored in the data node as the data in the global secondary index to achieve the creation of the global secondary index. After the filling is completed, the coordination node 1 begins to notify and wait for all (including itself) nodes to update the metadata version, thereby completing the creation of the global secondary index.
[0207] Exemplarily, the functions of the above-mentioned parsing module can be implemented by a parser deployed in the coordination node, the functions of the above-mentioned optimization module can be implemented by an optimizer deployed in the coordination node, and the functions of the above-mentioned execution module can be implemented by an executor deployed in the data node. Of course, the functions of the above-mentioned modules can also be implemented by other hardware devices, and no specific limitation is made in the embodiments of the present application.
[0208] See also Figure 7, Figure 7 A method flow chart of a method for creating an index in a distributed system provided in an embodiment of the present application. The method can be implemented by a coordination node in a distributed system, for example, by a processor in the coordination node, or by a logical function module in the coordination node. The method includes:
[0209] S701. The coordinating node receives a request to create a global secondary index GSI.
[0210] In an embodiment of the present application, a user can log in to a client, connect to a distributed system, and input a statement to create a GSI. The distributed system includes a plurality of nodes forming a node cluster, and the node cluster may include at least one coordination node and at least one data node. The coordination node is mainly responsible for guiding the relevant nodes to perform data processing and calculation. The data node is mainly responsible for storing data and calculation.
[0211] When the user inputs a statement to create a GSI, there is a coordination node in the distributed system that can receive the statement to create the GSI, and the coordination node that receives the statement to create the GSI is responsible for the entire GSI creation process. It can be understood that when the coordination node receives the statement to create the GSI input by the user, it can be determined that the GSI creation request has been received.
[0212] Optionally, the statement for creating a GSI input by the user may indicate the target data table for the GSI. The target data table may be any base table or several base tables of the distributed system, so that the distributed system can determine which data table needs to be used to create the GSI.
[0213] In the embodiment of the present application, the user may also input a delete, modify, update (IUD) statement, so that the distributed system may have a coordination node that can receive the IUD statement, and the coordination node that receives the IUD statement is responsible for the IUD operation on the data table.
[0214] For the sake of distinction, the coordination node that receives the statement of creating GSI input by the user may be defined as coordination node 1, and the coordination node that receives the statement of IUD input by the user may be defined as coordination node 2. Figure 8 As shown, the statement for creating a GSI input by the user is sent to the coordination node 1, so that the coordination node 1 can execute the index creation method in the distributed system provided by the present application.
[0215] S702: The coordinating node responds to the GSI creation request and sends first instruction information to all other nodes, where the first instruction information is used to instruct all other nodes to create and initialize metadata of the GSI.
[0216] In an embodiment of the present application, when the coordinating node is responsible for creating the GSI, the coordinating node may send a first instruction message to all other nodes. The all other nodes include other coordinating nodes and all data nodes. The first instruction message is used to instruct each of the all other nodes to create and initialize metadata related to the GSI.
[0217] Optionally, the coordinating node can start transaction 1 to submit transaction 1 after notifying and waiting for all nodes to complete the initialization and setting of GSI metadata. A transaction is a completed business logic, and transaction 1 here can be understood as the business logic that the coordinating node needs to wait for the completion of GSI metadata initialization of all nodes.
[0218] like Figure 8 As shown, after coordinating node 1 starts transaction 1, coordinating node 1 will send creation commands to coordinating node 2 and data node 1 respectively to instruct coordinating node 2 and data node 1 to complete the creation and initialization of metadata of GSI respectively. Among them, data node 1 can be any data node in the distributed system. Coordinating node 2 can be any coordinating node in the distributed system except coordinating node 1.
[0219] Optionally, each of all other nodes may perform GSI-related metadata creation and initialization upon receiving the first instruction information. After completing GSI-related metadata creation and initialization, each node may set the metadata version of the GSI to be writable but not readable (write only).
[0220] As a method, each of all other nodes can feed back first feedback information to the coordination node after completing the GSI metadata creation, initialization and version setting. The first feedback information is used to indicate that the GSI-related metadata creation and initialization have been completed. Figure 8 As shown, after completing the creation and initialization of metadata related to the GSI, the coordination node 2 and the data node 1 will each return a processing result indicating the completion of the initialization to the coordination node 1.
[0221] As another method, a preset processing time can be set for each of all other nodes, and each node needs to complete GSI metadata creation, initialization and version setting within the preset processing time. If a node fails to complete GSI metadata creation, initialization and version setting within the preset processing time, the current GSI online creation is stopped, and the coordinating node restarts the GSI online creation process, that is, re-responds to the GSI creation request and sends the first instruction information to all other nodes.
[0222] Optionally, if a node fails to complete creation, initialization, and version setting within a preset processing time, the node can feed back an indication message to the coordination node, and the indication message is used to indicate that the GSI metadata creation, initialization, and version setting of the node have failed. The coordination node can thus terminate the current GSI online creation process and restart the GSI online creation process. It can be understood that the embodiment of the present application does not limit the feedback method of each of the other nodes after executing the GSI metadata creation, initialization, and version setting, and it can also be other methods besides the above methods, or it can be that no feedback operation is performed.
[0223] S703: When the coordination node determines that all other nodes have completed the creation and initialization of the metadata of the GSI, the coordination node completes the creation and initialization of the metadata of the GSI on the coordination node.
[0224] In the embodiment of the present application, the coordinating node starts to create and initialize the metadata of its own GSI only after confirming that all other nodes have completed the creation and initialization of the metadata of the GSI. After completing the creation and initialization of the metadata related to the GSI, the coordinating node sets the metadata version of the GSI to be writable but not readable (write only). The metadata version of the GSI is now globally unified. In this way, data consistency is achieved under the metadata non-asynchronous (synchronous) update mechanism, ensuring high availability in the process of online creation of the GSI.
[0225] Optionally, the coordinating node may confirm that all other nodes have completed the creation and initialization of the metadata of the GSI when receiving the first feedback information sent by all other nodes.
[0226] Optionally, the coordination node may also automatically confirm that all other nodes have completed the creation and initialization of the metadata of the GSI after waiting for the above-mentioned preset processing time. Optionally, if the coordination node receives an initialization failure indication message from a certain node during the waiting period for the above-mentioned preset processing time, it can be confirmed that not all nodes have completed the creation and initialization of the metadata of the GSI. At this time, the coordination node may terminate the current GSI online creation process and restart the GSI online creation process, that is, re-respond to the GSI creation request and send the first instruction information to all other nodes.
[0227] The embodiment of the present application does not limit the method in which the coordinating node determines that all other nodes have completed the metadata creation and initialization of the GSI, which may also be other methods except the above confirmation method.
[0228] It can be understood that, unlike the asynchronous update of metadata in related technologies, that is, a specific node first completes the creation and initialization of GSI metadata, and then notifies other nodes through a third-party node / tool to complete the creation and initialization of GSI metadata, the coordination node in this solution first notifies and waits for all other nodes to complete the creation and initialization of GSI metadata, and then synchronously completes the creation and initialization of its own GSI metadata, thereby realizing a non-asynchronous update mechanism for metadata in the process of online creation of GSI. And because the node that executes GSI online creation in this solution is not a specific node, but any coordination node in the cluster can execute it after receiving the creation request. In this way, there will be no frequent additional burden on a certain node due to the fixed execution of GSI online creation, and there is no need to introduce a third-party node / tool with high concurrent access load to coordinate metadata updates. In this way, high concurrent performance under large-scale clusters can be effectively guaranteed.
[0229] It can be understood that when the coordinating node completes its own GSI metadata creation, initialization and version setting, it can be considered that the GSI metadata initialization of all nodes has been completed and transaction 1 has been implemented. At this time, the coordinating node can submit transaction 1 to end the transaction.
[0230] S704: The coordinating node sends a second instruction message to all other nodes, where the second instruction message is used to instruct all other nodes to wait for the current active transaction to be completed.
[0231] In the embodiment of the present application, when the metadata initialization of the GSI of all nodes is completed, the coordinating node can continue to send the second instruction information to all other nodes. The second instruction information is used to instruct each of all other nodes to wait for all currently active DML transactions on the target data table to end. In this solution, active transactions only refer to transactions that have not yet ended or been submitted.
[0232] Optionally, the coordinating node can start transaction 2, notify and wait for all nodes to complete all currently active transactions. Figure 8 As shown, after coordinating node 1 starts transaction 2, coordinating node 1 will send wait commands to coordinating node 2 and data node 1 respectively, to instruct coordinating node 2 and data node 1 to wait for all currently active transactions to be completed.
[0233] Optionally, upon receiving the second instruction information, each of all other nodes may execute the command and wait for all currently active DML transactions on the target data table to end. As a method, each of all other nodes may feed back the second feedback information to the coordination node after completing the waiting for all currently active transactions. The second feedback information is used to indicate that all currently active DML transactions on the target data table have ended. Figure 8As shown, after waiting for all currently active DML transactions on the target data table to end, the coordinating node 2 and the data node 1 will each return a processing result indicating that all currently active transactions have ended to the coordinating node 1.
[0234] As another way, a preset processing time can be set for each of all other nodes, and each node needs to complete the waiting of all currently active transactions within the preset processing time. If a node fails to complete the waiting of all currently active transactions within the preset processing time, the GSI online creation is stopped, and the coordination node restarts the GSI online creation process, that is, responds to the GSI creation request again and sends the first instruction information to all other nodes. Optionally, the preset processing time here can be the same as or different from the preset processing time set in the aforementioned GSI metadata initialization phase.
[0235] Optionally, if a node fails to complete the waiting of all currently active transactions within the preset processing time, the node can feed back an indication message to the coordination node, which is used to indicate that the waiting of all currently active transactions of the node has failed. Thus, the coordination node can terminate the current GSI online creation process and restart the GSI online creation process.
[0236] It can be understood that the embodiment of the present application does not limit the feedback method of each node among all other nodes after executing the waiting of all currently active transactions, and it can also be other methods besides the above methods, or it can also be that no feedback operation is performed.
[0237] S705 . When the coordinating node confirms that all other nodes have completed waiting for all currently active transactions, the coordinating node waits for completion of the current active transaction of the coordinating node.
[0238] In the embodiment of the present application, after the coordinating node confirms that all currently active transactions on all other nodes have ended, it starts waiting for all currently active DML transactions on its own node on the target data table to end.
[0239] Optionally, the coordinating node may confirm that all other nodes have completed the creation and initialization of the metadata of the GSI when receiving the second feedback information sent by all other nodes.
[0240] Optionally, the coordination node may also automatically confirm that all other nodes have completed waiting for all currently active transactions after waiting for the above-mentioned preset processing time. Optionally, if the coordination node receives a waiting failure indication message fed back by a certain node during the waiting period for the above-mentioned preset processing time, it can be confirmed that not all nodes have completed waiting for all currently active transactions. At this time, the coordination node can terminate the current GSI online creation process and restart the GSI online creation process, that is, re-respond to the GSI creation request and send the first instruction information to all other nodes.
[0241] The embodiment of the present application does not limit the method in which the coordinating node determines that all other nodes have completed waiting for all currently active transactions, and it may also be other methods besides the above confirmation method.
[0242] S706: The coordinating node performs data filling of the GSI.
[0243] It can be understood that when all currently active DML transactions of the coordinating node itself on the target data are completed, it can be considered that all currently active DML transactions of all nodes on the target data have been completed. In this way, the coordinating node can continue to execute the process of online creation of GSI. At this time, the coordinating node can obtain the data visible to the current transaction, such as through a snapshot, and then obtain the required data from the data in the target data table under the snapshot and fill it into the GSI. In this way, during the process of online creation of GSI by the coordinating node, after confirming that all nodes (including itself) have completed the currently active transactions, it will start to execute the data filling of GSI, which will not hinder the normal execution of user DML transactions and ensure high availability in the process of online creation of GSI.
[0244] Optionally, the coordination node can obtain the required relevant data from each data node where the target data table is located, and then send it to the corresponding destination data node according to the distribution key, and fill it into the data shard of the GSI corresponding to the destination data node, forming a Figure 6 GSI shards in datanode 1 are shown.
[0245] As an example, when the data in the target data table and GSI are distributed and stored on multiple different nodes based on the hash distribution rule, the coordination node will calculate the address information between the data nodes through the hash algorithm according to the distribution key value of the target data table obtained, and insert the obtained data and the calculated address information into the GSI of the data node, thereby realizing data filling on the GSI.
[0246] Optionally, when the coordination node confirms that the data filling of the relevant node (such as the destination data node corresponding to the above GSI) is completed, it is confirmed that the data in the target data table under the snapshot has been scanned and the data filling of the GSI is completed.
[0247] As a method, after the destination data node completes data filling, it can feedback a message indicating that data filling is completed to the coordination node, so that when the coordination condition receives the feedback information from the destination data node, it can confirm that data filling of the destination data node is completed. Optionally, when the above GSI corresponds to the destination data node including coordination node 2 and data node 1, Figure 8 As shown, the coordination node 1 can perform data filling on the GSI on the coordination node 2 and the data node 1. After the coordination node 2 and the data node 1 complete the data filling, each returns a processing result indicating that the data filling has been completed to the coordination node 1.
[0248] The embodiment of the present application does not limit the feedback method of the destination data node after completing data filling. It can also be other methods, such as no feedback, or feedback only when data filling fails.
[0249] The embodiment of the present application does not limit the way in which the coordinating node determines that the destination data node has completed data filling. It may also use other methods, such as waiting for a preset processing time to automatically confirm that the destination data node has completed data filling.
[0250] S707. The coordinating node sends third instruction information to all other nodes, where the third instruction information is used to instruct all other nodes to update metadata of the GSI.
[0251] In the embodiment of the present application, when the data filling of the GSI is completed, the coordinating node may send a third instruction message to all other nodes, wherein the third instruction message is used to instruct each of all other nodes to update the metadata of the GSI to an available (public) state.
[0252] like Figure 8 As shown, the coordination node 1 will send a creation completion notification (third instruction information) to the coordination node 2 and the data node 1 respectively to instruct the coordination node 2 and the data node 1 to update the metadata version. The creation completion notification sent by the coordination node 1 may include a metadata version modification command.
[0253] When receiving the third instruction information, each of all other nodes may set the metadata version of the GSI to be available (public). As a way, each of all other nodes may feedback the third feedback information to the coordination node after completing the available (public) version setting. The third feedback information is used to indicate that the metadata version update of the GSI is completed. Figure 8 As shown, after completing the metadata version update of the GSI, the coordination node 2 and the data node 1 will each return a processing result indicating the completion of the metadata version update of the GSI to the coordination node 1.
[0254] As another way, a preset processing time can be set for each of all other nodes, and each node needs to complete the setting of the available (public) version of the GSI metadata within the preset processing time. If a node fails to complete the setting of the available (public) version of the GSI metadata within the preset processing time, the current GSI online creation is stopped, and the coordinating node restarts the GSI online creation process, that is, re-responds to the GSI creation request and sends the first instruction information to all other nodes. Optionally, the preset processing time here can be the same as or different from the preset processing time set above.
[0255] Optionally, if a node fails to complete the setting of the available (public) version of the GSI metadata within the preset processing time, the node can feedback an indication information to the coordination node, and the indication information is used to indicate that the setting of the available (public) version of the GSI metadata of the node has failed. Thus, the coordination node can terminate the current GSI online creation process and restart the GSI online creation process.
[0256] It can be understood that the embodiment of the present application does not limit the feedback method of each of all other nodes after executing the available (public) version setting of the GSI metadata, and it can also be other methods besides the above method, or it can also be that the feedback operation is not performed.
[0257] S708: When the coordinating node determines that all other nodes have completed the metadata update of the GSI, the coordinating node completes the metadata update of the GSI on the coordinating node.
[0258] In the embodiment of the present application, after the coordinating node confirms that the metadata of the GSI on all other nodes has been updated to the available (public) version, it starts to complete the metadata version update of the GSI on its own node. That is, the metadata version of the GSI of its own node is set to available (public). The metadata version of the GSI is globally unified at this time. In this way, data consistency is achieved under the metadata non-asynchronous (synchronous) update mechanism, ensuring high availability in the process of online GSI creation.
[0259] Optionally, the coordinating node may confirm that all other nodes have completed the update of the available (public) version of the metadata of the GSI when receiving the third feedback information sent by all other nodes.
[0260] Optionally, the coordination node may also automatically confirm that all other nodes have completed the update of the GSI's available (public) version of metadata after waiting for the above-mentioned preset processing time. Optionally, if the coordination node receives a version update failure indication message from a node during the waiting period for the above-mentioned preset processing time, it can be confirmed that not all nodes have completed the update of the GSI's available (public) version of metadata. At this time, the coordination node can terminate the current GSI online creation process and restart the GSI online creation process, that is, re-respond to the GSI creation request and send the first instruction information to all other nodes.
[0261] The embodiment of the present application does not limit the method in which the coordinating node determines that all other nodes have completed the update of the available (public) version of the metadata of the GSI. It may also be other methods except the above confirmation method.
[0262] It can be understood that when the coordinating node completes the metadata version update of its own GSI, it can be considered that the metadata version update of the GSI of all nodes has been completed. At this time, the coordinating node can submit transaction 2 to end the transaction, thereby completing the online creation of the GSI.
[0263] In the embodiment of the present application, after completing the online creation of the GSI, the coordination node may return the creation result to the client where the user is located, so that the user can complete a quick query of other columns other than the distribution key based on the secondary index.
[0264] It can be understood that since the present application can ensure data consistency through a metadata asynchronous (synchronous) update mechanism, metadata version transition can be simplified, that is, there is no need to add the aforementioned metadata version delete only.
[0265] In some embodiments, in order to reduce changes to related technologies, the original metadata version delete only may be retained, and the above-mentioned metadata version delete only update steps may be repeated. Exemplarily, the coordinating node may send a fourth instruction message to all other nodes, and the fourth instruction message is used to instruct all other nodes to create and initialize the metadata of the GSI, and set the metadata version of the GSI to the delete only version. When the coordinating node determines that all other nodes have completed the metadata delete only version setting of the GSI, the coordinating node completes the metadata creation and initialization of the GSI on the coordinating node and the metadata delete only version setting. After confirming that all nodes (including itself) have completed the metadata delete only version setting of the GSI, the coordinating node executes subsequent writable but not readable (write only) version updates, current active transaction waiting, data filling, and available (public) version update processes.
[0266] As an example, when the coordination node determines that the coordination node and all other nodes have completed the delete only version setting of the global secondary index, the coordination node can send the fifth instruction information to all other nodes, and the fifth instruction information is used to instruct all other nodes to update the metadata of the GSI and update the metadata version of the GSI to the write only version. When the coordination node determines that all other nodes have completed the metadata write only version update of the GSI, it completes the metadata update of the GSI and the metadata write only version update on its own node. After confirming that the metadata write only version update of all nodes (including itself) is completed, the coordination node sends the above second instruction information to all other nodes, and the second instruction information is used to instruct all other nodes to wait for the current active transaction to be completed. When the coordination node confirms that all other nodes have completed the waiting of all current active transactions, it waits for the current active transaction of the coordination node to be completed on its own node. After confirming that the current active transactions of all nodes (including itself) are completed, the coordination node performs data filling of the GSI. After confirming that the data filling is completed, the coordination node sends the above third instruction information to all other nodes, and the third instruction information is used to instruct all other nodes to update the metadata of the GSI and update the metadata version of the GSI to the public version. When the coordinating node determines that all other nodes have completed the public version update of the metadata, it updates the metadata of the GSI on its own node and updates the metadata version of the GSI to the public version.
[0267] Optionally, the solution can also follow the user DML transaction priority principle, that is, the coordinating node first notifies and waits for other nodes to update to the delete-only version, and then completes the delete-only version update on its own node. It needs to obtain a metadata lock and wait for the transaction to complete (the transaction of the metadata version <= delete-only version ends), and then the coordinating node can enter the next version of write-only notification and wait, and write-only synchronization update on its own node. In this way, during the online creation process of GSI, the normal execution of user DML transactions is not hindered, ensuring high availability during the creation process.
[0268] As an example, the coordinating node may send a sixth instruction message to all other nodes when it is determined that the coordinating node and all other nodes have completed the delete only version setting of the global secondary index. The sixth instruction message is used to instruct all other nodes to wait for the current active transaction to be completed. When the coordinating node confirms that all other nodes have completed the waiting for all currently active transactions, it waits for the current active transaction of the coordinating node to be completed. After confirming that the current active transactions of all nodes (including itself) are completed, the coordinating node sends the above-mentioned fifth instruction message to all other nodes. The fifth instruction message is used to instruct all other nodes to update the metadata of the GSI and update the metadata version of the GSI to the write only version. When the coordinating node determines that all other nodes have completed the write only version update of the metadata of the GSI, it completes the metadata update of the GSI on the coordinating node and the metadata write only version update on its own node.
[0269] The index creation method provided by this application is described in detail below using an example.
[0270] As an example, the index creation method provided in this application can be applied to a student registration system based on a distributed system architecture. For example, the student registration system has a data table. The table name of the data table is A, and the attribute columns include: studentid student ID (distribution key); name student name; classid class ID. The data of the entire data table A is shown in Table 1:
[0271] Table 1
[0272] StudentID name classid 1 Xiao Ming 11 2 Xiao Wang 12 3 Xiao Zhang 13 4 Xiao Li 9 5 Xiao Yang 8 6 Little Red 7 … … …
[0273] Among them, studentid is a self-incrementing and unique attribute, so data table A adopts hash distribution, and distributes data relatively evenly to each node of the distributed system through the hash algorithm and based on the studentid column. For example, the data distribution of data table A in the distributed system can be as follows Fig. 9 As shown. Data table A is sharded into shard 1 of table A (including data of studentid[1, 2, ...]), shard 2 of table A (including data of studentid[3, 4, ...]), and shard 3 of table A (including data of studentid[5, 6, ...]). Shard 1 of table A is stored in data node 1, shard 2 of table A is stored in data node 2, and shard 3 of table A is stored in data node 3.
[0274] When a user inputs a request to create a global secondary index on data table A, a coordination node (server or virtual machine on the server) in the student registration system can receive the request and be responsible for creating the global secondary index of data table A.
[0275] The following example introduces this solution by taking the case where a user creates a global secondary index a on table A, and the attributes of the global secondary index a are: classid class ID (index key and distribution key); name student name (additional key).
[0276] The statement for creating a global secondary index a can be: "CREATE GLOBAL INDEX CONCURRENTLY aon A(classid)CONTAINING(name)DISTRIBUTE BY HASH(classid)", where CREATE GLOBALINDEX means creating a global secondary index, CONTAINING refers to an additional key, and DISTRIBUTE BY HASH means distribution in hash distribution mode. The meaning of this statement is: on the base table A whose distribution key is class ID, create a global secondary index a with index key and distribution key as class ID, distribution mode as hash distribution, and additional key as student name.
[0277] First, the request for creating a global secondary index input by the user is sent to a coordination node in the student registration system. This coordination node can serve as coordination node 1 responsible for creating the global secondary index a.
[0278] Then the coordination node 1 starts transaction one, notifies all nodes waiting to complete the initialization of the global secondary index a and then commits transaction one. In this step, the coordination node 1 sends a creation instruction to all other coordination nodes and data nodes. Each other coordination node and data node initializes the metadata of the global secondary index a and sets the metadata version to writable but not readable (write only), and then feeds back to the coordination node 1 for processing. Among them, the setting of writable but not readable (write only) can be set to FALSE by setting the status flag (indisvalid) corresponding to the global secondary index a in the system table. During the entire process of creating and initializing the global secondary index a, a shared (SHARE LOCK) lock can be added to the data table A. The SHARELOCK lock can also be called a read lock, which is used to block other operations except query operations, such as IUD operations, in order to ensure that the data in the data table A remains unchanged.
[0279] After coordinating node 1 confirms that it has received feedback from all other nodes that the above operations have been completed, coordinating node 1 creates and initializes the metadata of global secondary index a and sets the metadata version to writable but not readable (write only), and in this process, a SHARE LOCK can be added to data table A. The coordinating node commits transaction 1, and the metadata version of global secondary index a is now globally unified.
[0280] Next, coordination node 1 starts transaction 2, notifies and waits for all nodes to complete waiting for all currently active transactions. In this step, coordination node 1 generates a wait command and sends it to all other coordination nodes and data nodes. The wait command can be an SQL statement: ALTER TABLE{A}GSIWAITALL. Each node executes the command and waits for all currently active DML transactions on data table A to end. Among them, waiting for all DML transactions to be implemented can be by waiting for transactions that conflict with the SHARE LOCK lock on data table A to be completed. The transactions that conflict with the SHARE LOCK lock here can be understood as other operations other than the query operation blocked above, such as IUD operations. After waiting is completed, a shared update exclusive (SHAREUPDATE EXCLUSIVE LOCK) lock is added to data table A, so that the read operation and DML operation of data table A will not be blocked, but other operations, such as DDL operations, will be blocked. Then feedback is given to coordination node 1 that the above operations are completed. After coordinating node 1 confirms that it has received feedback from all other nodes that the above operations have been completed, coordinating node 1 waits for all currently active DML transactions on its own node on data table A to end, and adds a SHARE UPDATE EXCLUSIVE LOCK to data table A. Alternatively, unlike the aforementioned method where each node needs to wait for the completion of active transactions and lock them before giving feedback to coordinating node 1, as another case, coordinating node 1 can also wait for all nodes to complete active transactions first, and then add a SHARE UPDATE EXCLUSIVE LOCK to each node after confirming that it has received feedback from all other nodes that the above operations have been completed. That is, waiting for the completion of active transactions and locking operations can be performed separately.
[0281] Then, the coordination node 1 organizes the data of data table A to be filled into the global secondary index a. In this step, the coordination node 1 first adds a row exclusive lock (ROW EXCLUSIVE LOCK) to the global secondary index a. Here, the row exclusive lock is used to achieve non-blocking IUD operations on the global secondary index a but blocking other operations, such as DDL operations. Then the coordination node 1 obtains the current snapshot, and starts to organize the acquisition of the data required for the global secondary index a (the columns corresponding to the distribution key, index key, and additional key) from the data table A under the snapshot and fills it into the global secondary index a.
[0282] The data can be filled in through the SQL statement: "INSERT INTO a (classid, name, location information, version information) SELECT classid, name, location information, version information FROM A". This statement means selecting the class ID, student name, location information and version information from the data table A and inserting them into the global secondary index a. The location information is used to indicate the location of the data in the data table A, including the node information where the data is located (xc_node_hash) and the storage location in the node (ctid). The data node where the data should be inserted is obtained by the value of the distribution key classid of the global secondary index a under the hash algorithm.
[0283] When the coordination node 1 confirms that all the data under the snapshot has been scanned and filled into the global secondary index a, the data filling is completed.
[0284] In this application, during the data filling process of the data node of the global secondary index a, the data modification caused by the IUD operation that occurs synchronously in the data table A needs to be reflected in the global secondary index a accordingly to ensure the consistency of the data after the creation is completed.
[0285] For example, during the data filling process, when the same user or other users input an IUD operation request on the data table A, the IUD operation request will also be sent to a coordination node in the student registration system. This coordination node can serve as coordination node 2 responsible for performing IUD operations on data table A. Optionally, coordination node 2 and coordination node 1 can be the same or different. Coordination node 2 can issue a command to the corresponding data node based on the IUD operation request, and the corresponding data node performs IUD processing on the data. At this time, a data node may need to synchronously perform data filling and IUD processing on the global secondary index a.
[0286] In one scenario, taking the IUD operation as an INSERT operation as an example, after data table A processes the INSERT operation to insert a new row of data (tuple), the data node of the global secondary index a can obtain the data required by the global secondary index a (columns corresponding to the partial key, index key, and additional key) and insert it into the global secondary index a.
[0287] As an example, take inserting a row of data tuples (2, Xiao Wang, 12) into data table A. The data tuple insertion operation into data table A can be performed through the SQL statement: "INSERT INTO A (studentid, name, classid) VALUES (2, Xiao Wang, 12) RETURNING studentid, name, classid, location information, version information". The meaning of this statement is to insert the tuple (2, Xiao Wang, 12) to be inserted, and at the same time return the data content on all columns of the tuple, including class ID, student name, student ID, location information and version information. The SQL statement can be calculated by the coordination node 2 according to the distribution key student ID hash algorithm and sent to the corresponding data node for execution.
[0288] Then, the tuple insertion operation of the global secondary index a can be performed through the SQL statement: "INSERT INTO a(classid, name, location information, version information) VALUES($3, $2, $4, $5)". The meaning of this statement is to extract the required class ID, student name, location information and version information from the data content of all columns of the tuple returned above, and form a tuple to be inserted into the global secondary index a. This SQL statement is calculated by the coordination node 2 or the data node that performs the insertion operation of the data table A according to the distribution key class ID hash algorithm and sent to the corresponding data node for execution. After the global secondary index a is created, the tuples added to the data table A during the creation of the global secondary index a also have corresponding tuples in the global secondary index a, and the data remains consistent. Among them, $X is used to indicate the extraction of data information of the Xth column from all columns returned by the aforementioned RETURNING. For example, $3 is used to indicate the extraction of data information of the third column (i.e., classid) from the "studentid, name, classid, location information, version information" returned by the aforementioned RETURNING.
[0289] In another scenario, taking the IUD operation as a DELETE operation as an example, after data table A processes the DELETE operation to delete a row of old data (tuple), the data node of the global secondary index a can delete the corresponding data row in the global secondary index a.
[0290] As an example, take the case of deleting the tuple (2, Xiao Wang, 12) from data table A with the condition of studentid=2. The tuple deletion operation on data table A can be performed through the SQL statement: "DELETE FROM A WHERE studentid=2RETURNING studentid, name, classid, location information, version information". The meaning of this statement is to delete the tuple (2, Xiao Wang, 12) according to the deletion condition, and return the data content on all columns, including class ID, student name, student ID, location information and version information. Since the deletion condition for data table A includes the distribution key (student ID), the SQL statement can be calculated by the coordination node 2 according to the distribution key student ID hash algorithm and sent to the corresponding data node for execution.
[0291] Then, the data deletion operation on the global secondary index a can be performed through the SQL statement: "DELETE FROM a WHEREclassid=$3 AND name=$2 AND location information=$4 AND version information=$5". The meaning of this statement is to extract the required class ID, student name, location information and version information from the data content of all the columns returned above as the deletion conditions, and delete the corresponding tuple (12, Xiao Wang, location information, version information) in the global secondary index a. The SQL statement is sent by the coordination node 2 or the data node that executes the deletion operation of the data table A to the corresponding data node to perform the deletion operation according to the distribution key class ID hash algorithm.
[0292] It should be noted that when the data node of the global secondary index a receives an SQL request to delete the tuple (12, Xiao Wang, location information, version information), the following two situations may occur:
[0293] Case 1: The tuple (12, Xiao Wang, location information, version information) has been processed by the data filling process of online GSI creation and filled into the global secondary index a. When the data node of global secondary index a deletes the data row, it can find this tuple from the data of global secondary index a and delete it normally. In this way, when the data node of global secondary index a receives an SQL request to delete the tuple, Fig.11 As shown, the data node of the global secondary index a can first try to find the tuple to be deleted. If the search is successful, it means that the tuple to be deleted has been filled into the global secondary index a, and the data node of the global secondary index a can delete the tuple to be deleted normally.
[0294] Case 2: The tuple (12, Xiao Wang, location information, version information) has not been processed by the data filling process of online GSI creation, and has not been filled into the global secondary index a. When the data node of the global secondary index a deletes the data row, it cannot find this tuple.
[0295] At this time, the present application provides a data processing method, such as Fig.11 As shown, the data node of the global secondary index a can first try to find the tuple to be deleted. If the search is unsuccessful, it can first determine whether the global secondary index a is still being created online. If not, it means that the tuple to be deleted does not exist and the request may be incorrect. If so, it means that the tuple to be deleted has not yet been filled into the global secondary index a. At this time, the data information of the deleted row can be obtained from the WHERE deletion condition of the above SQL statement "DELETE FROM a WHERE classid=$3 AND name=$2 AND location information=$4 AND version information=$5", which contains the data content of all columns corresponding to the deleted row. This data information can be used to fill in and piece together the overall data of the tuple to be deleted (12, Xiao Wang, location information, version information). As shown Fig.11 As shown, the assembled tuple to be deleted is first inserted into the global secondary index a, and then the tuple is deleted immediately. At this time, the deletion effect of the tuple (12, Xiao Wang, location information, version information) can be presented in the global secondary index a.
[0296] Correspondingly, if Fig.12 As shown, the data filling process of creating GSI online is able to scan the above-mentioned deleted tuple (2, Xiao Wang, 12) based on the snapshot to obtain the visible data in the data table A. Therefore, when the corresponding data node wants to insert the corresponding tuple (12, Xiao Wang, location information, version information) into the global secondary index a, the storage location with the same index key can be quickly located in the global secondary index a according to its index key (class ID). After scanning and comparing, an insertion conflict is found. If there are rows (12, Xiao Wang, location information, version information) with the same data content on all columns (distribution key, index key and additional key, location information, version information) in the global secondary index a, the insertion is skipped and returned directly. It can be understood that if no insertion conflict is found after scanning and comparing, the data node of the global secondary index a can be inserted into the tuple normally.
[0297] In this way, after the global secondary index a is created, if the data row in table A is deleted during the creation of the global secondary index a, the global secondary index a will also delete the data row accordingly, and the data will remain consistent.
[0298] In another scenario, taking the IUD operation as an UPDATE operation as an example, after data table A processes the UPDATE operation to update a row of data (tuple), the data node of the global secondary index a can update the corresponding data row in the global secondary index a.
[0299] As an example, take the case of updating the tuple (2, Xiao Wang, 12) to (2, Xiao Li, 12) for data table A with studentid=12 as the condition. The tuple update operation on data table A can be performed through the SQL statement: "UPDATE A SET name="Xiao Li" WHERE studentid=12 RETURNING studentid_new, name_new, classid_new, location information_new, version information_new, studentid, name, classid, location information, version information". The meaning of this statement is to update the tuple (2, Xiao Wang, 12) to (2, Xiao Li, 12) according to the update condition, and return the data content before and after the update on all columns, including class ID, student name, student ID, location information and version information. The SQL statement can be calculated by the coordination node 2 according to the distribution key student ID hash algorithm and sent to the corresponding data node for execution.
[0300] Then, the data update operation on the global secondary index a can be performed through the SQL statement: "UPDATE a SET classid=$3 AND name=$2AND location information=$4 AND version information=$5 WHERE classid=$8 AND name=$7 AND location information=$9 AND version information=$10". The meaning of this statement is to extract the required class ID, student name, location information and version information from the data content of all the columns returned above as update conditions, and update the corresponding tuple (12, Xiao Wang, location information, version information) in the global secondary index a to (12, Xiao Li, location information_new, version information_new). The SQL statement is sent by the coordination node 2 or the data node that executes the update operation of the data table A to the corresponding data node to perform the update operation according to the distribution key class ID hash algorithm.
[0301] When the data node performs corresponding data updates on the global secondary index a, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. That is, first delete the old tuple (12, Xiao Wang, location information, version information), and then insert the new tuple (12, Xiao Li, location information_new, version information_new). It should be noted that when deleting the old tuple, the above-mentioned DELETE operation situation 2 may occur, that is, the situation where the corresponding tuple cannot be found in the global secondary index a. The corresponding processing method is the same as above and will not be repeated.
[0302] In this way, after the global secondary index a is created, the data row in the data table A that is updated during the creation of the global secondary index a is also updated by the global secondary index a accordingly, and the data remains consistent.
[0303] In this way, during the data filling process, if there is a data modification caused by the IUD operation that occurs synchronously in the data table A, the data modification can be completed in the global secondary index a in the above manner to ensure the consistency of the data after the global secondary index a is created. Thus, the data filling in the online creation process of the global secondary index a can be accurately completed without hindering the normal execution of the user's DML transaction. Finally, the coordination node 1 notifies and waits for the metadata update of the global secondary index a to be completed on all nodes, and commits transaction two. In this step, the coordination node 1 generates a metadata version modification command and sends it to all other coordination nodes and data nodes. The metadata version modification command can be an SQL statement ALTER INDEX{a}GSIVAILD. Each node executes the command, sets the metadata version to available (public), and then feeds back to the coordination node 1 for processing. Among them, the setting of the available (public) version can be by setting the status flag (indisvalid) corresponding to the global secondary index a on the system table to TRUE. After confirming the feedback from all other nodes, the coordination node 1 sets its own metadata version to available (public). The coordination node commits transaction two, and the metadata version of the global secondary index a is now globally unified.
[0304] The creation of global secondary index a is completed.
[0305] For example, after the online creation of the global secondary index a on the data table A is completed, the data distribution of the global secondary index a in the distributed system can be as follows: Fig.10 As shown. The global secondary index a is sharded into shard 1 of the global secondary index a (including data of classid[13, 12, ...]), shard 2 of the global secondary index a (including data of classid[11, 9, ...]), and shard 3 of the global secondary index a (including data of classid[8, 7, ...]). Shard 1 of the global secondary index a is stored in data node 1, shard 2 of the global secondary index a is stored in data node 2, and shard 3 of the global secondary index a is stored in data node 3.
[0306] like Fig.10 As shown in the figure, the shards of the global secondary index a are all data structures sorted by the index key classid defined by the user. In this way, when the user queries based on classid, the desired data can be quickly queried based on the global secondary index a.
[0307] As another example, the index creation method provided in this application can also be applied to a shopping mall cashier system based on a distributed system architecture. For example, the shopping mall cashier system has a data table. The table name of the data table is B, and the attribute columns include: counterid cashier ID (distribution key); fno mall floor number; cashierid cashier ID. The data of the entire data table B is shown in Table 2:
[0308] Table 2
[0309] counterid fno cashierid 1 1 STF100023 1 1 STF100025 2 1 STF231567 3 2 MNG695478 4 3 STF777777 4 3 STF666666 … … …
[0310] Among them, counterid is the auto-increment distribution key. Since the total number of cash registers is relatively fixed, data table B uses range distribution.
[0311] When the user inputs a request to create a global secondary index on data table B, a coordination node (server or virtual machine on the server) in the mall cashier system can receive the request and be responsible for creating the global secondary index of data table B.
[0312] The following example introduces this solution by taking the example of a user creating a global secondary index b on data table B, where the attributes of the global secondary index b are: cashierid cashier ID (index key, distribution key); counterid cashier ID (additional key); fno mall level number (additional key).
[0313] The creation statement can be: "CREATE GLOBAL INDEX CONCURRENTLY b on B(cashierid) CONTAINING(counterid, fno) DISTRIBUTE BY RANGE(cashierid)", where CREATE GLOBAL INDEX means creating a global secondary index, CONTAINING means additional key, and DISTRIBUTE BY RANGE means distribution by range distribution. The meaning of this statement is: on the base table B whose distribution key is cashier ID, create a global secondary index b with index key and distribution key as cashier ID, distribution mode as range distribution, additional key as cashier ID, and number of mall floors.
[0314] First, a request for creating a global secondary index input by a user is sent to a coordination node in the mall cashier system. This coordination node can be responsible for creating coordination node 1 of the global secondary index b.
[0315] Then the coordination node 1 starts transaction one, notifies and waits for all nodes to complete the initialization of the global secondary index b before submitting transaction one. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 notifies and waits for each node to initialize the metadata of the global secondary index b and sets the version to writable but not readable (write only), and submits transaction one. The setting of writable but not readable (write only) can be achieved by setting the status flag (indisvalid) corresponding to the global secondary index b on the system table to FALSE. During the entire process of creating and initializing the global secondary index b, a SHARE LOCK can be added to the data table B. The metadata version of the global secondary index b is now globally unified.
[0316] Next, coordination node 1 starts transaction 2, notifies and waits for all nodes to complete waiting for all currently active transactions. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 generates a waiting command ALTER TABLE{B}GSIWAITALL. Waiting for all DML transactions can be achieved by waiting for transactions that conflict with obtaining a SHARE LOCK lock on data table B to complete. Then add a SHARE UPDATE EXCLUSIVE LOCK to data table B. Coordination node 1 sends commands to all nodes, and waits for each node to complete waiting for the current active transaction to end, and then adds a SHARE UPDATE EXCLUSIVE LOCK to data table B. Alternatively, as another case, coordination node 1 can also wait for all nodes to complete active transactions first, and then uniformly add a SHARE UPDATE EXCLUSIVE LOCK to each node.
[0317] Then, coordination node 1 organizes the data of data table B to fill in the global secondary index b. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 can first add a ROW EXCLUSIVELOCK lock to the global secondary index b. Here, the row exclusive lock is used to achieve non-blocking IUD operations on the global secondary index b but blocking other operations, such as DDL operations. Then coordination node 1 obtains the current snapshot and starts to organize the acquisition of the data required for the global secondary index b (distribution key, index key, and additional key corresponding columns) from the data table B under the snapshot and fill it into the global secondary index b.
[0318] The data can be filled in through the SQL statement: "INSERT INTO b(cashierid, fno, counterid, location information, version information) SELECT cashiered, counterid, fno, location information, version information FROM B". This statement means selecting the cashier ID, mall floor number, cashier ID and version information from the data table B and inserting them into the global secondary index b. The location information is used to indicate the location of the data in the data table, such as the node information (xc_node_hash) where the data is located and the storage location (ctid) in the node. The data node where the data should be inserted is obtained by the value of the distribution key counterid of the global secondary index b under the range distribution algorithm.
[0319] When the coordination node 1 confirms that all the data under the snapshot has been scanned and filled into the global secondary index b, the filling is completed.
[0320] Similarly, during the filling process of the data nodes of the global secondary index b, the data modifications caused by the IUD operation that occurs synchronously in the data table B must also be reflected in the global secondary index b accordingly to ensure the consistency of the data after the creation is completed. For example, during the data filling process, when the same user or other users input an IUD operation request on the data table B, the IUD operation request will also be sent to a coordination node 2 in the mall cashier system. Optionally, coordination node 2 and coordination node 1 can be the same or different. Coordination node 2 can issue a command to the corresponding data node based on the IUD operation request, and the corresponding data node will perform IUD processing on the data. At this time, a data node may need to synchronously perform data filling and IUD processing on the global secondary index b.
[0321] In one scenario, when data table B processes an INSERT operation to insert a new row of data (tuple), the data node of the global secondary index a can obtain the data required by the global secondary index b (the columns corresponding to the distribution key, index key, and additional key) and insert it into the global secondary index b. As an example, take the insertion of the data tuple (2, 1, STF231567) into the base table B as an example. The data tuple insertion operation of data table B can be performed through the SQL statement: "INSERT INTO B (counterid, fno, cashierid) VALUES (2, 1, STF231567) RETURNING counterid, fno, cashierid, location information, version information". The meaning of this statement is to insert the tuple (2, 1, STF231567) to be inserted, and at the same time return the data content on all columns of the tuple, including the cashier ID, the number of mall floors, the cashier ID, the location information, and the version information. Its SQL statement can be calculated by the coordination node 2 according to the distribution key cashier ID range distribution algorithm and sent to the corresponding data node for execution.
[0322] Then, the tuple insertion operation of the global secondary index b can be performed through the SQL statement: "INSERT INTO a(cashierid, counterid, fno, location information, version information) VALUES($3, $1, $2, $4, $5)". The meaning of this statement is to extract the required cashier ID, cashier counter ID, number of mall floors, location information and version information from the above returned data content, and form a tuple to be inserted into the global secondary index b. The SQL statement is calculated by the coordination node 2 or the data node that executes the insert operation of the data table B according to the distribution key cashier ID range distribution algorithm and sent to the corresponding data node for execution. After the global secondary index b is created, the tuples added in the data table B during the creation of the global secondary index b also have corresponding tuples in the global secondary index, and the data remains consistent.
[0323] In another scenario, after data table B processes a DELETE operation to delete a row of old data (tuple), the data node of global secondary index a can delete the corresponding data row in global secondary index b. As an example, take the case of deleting the tuple (3, 2, MNG695478) from data table B with fno=2 as the condition. The tuple deletion operation on data table B can be performed through the SQL statement: "DELETE FROM B WHERE fno=2 RETURNING counterid, fno, cashierid, location information, version information". The meaning of this statement is to delete the tuple (3, 2, MNG695478) according to the deletion condition, and return the data content on all columns, including cashier ID, mall level, cashier ID, location information and version information. Since the deletion condition for data table B is the number of mall levels and does not contain the distribution key (cashier ID), the SQL statement needs to be broadcast by coordination node 2 to all data nodes to attempt to delete it.
[0324] Then the data deletion operation on the global secondary index b can be performed through the SQL statement: "DELETE FROM b WHEREcashierid=$3AND counterid=$1 AND fno=$2 AND location information=$4 AND version information=$5". The meaning of this statement is to extract the required cashier ID, cashier counter ID, mall floor number, location information and version information from the above returned data content as deletion conditions, and delete the corresponding tuple (MNG695478, 3, 2, location information, version information) in the global secondary index b. The SQL statement is calculated by the coordination node 2 or the data node that executes the deletion operation of the data table B according to the distribution key cashier ID range distribution algorithm and sent to the corresponding data node to execute the deletion operation.
[0325] Similarly, when the data node of the global secondary index b receives an SQL request to delete the tuple (MNG695478, 3, 2, location information, version information), the following two situations may occur:
[0326] Case 1: The tuple (MNG695478, 3, 2, location information, version information) has been processed by the data filling process of online GSI creation and filled into the global secondary index b. When the data node of the global secondary index b deletes the data row, this tuple can be found in the data of the global secondary index b, and the deletion is performed normally.
[0327] Case 2: The tuple (MNG695478, 3, 2, location information, version information) has not been processed by the data filling process of creating GSI online, and has not been filled into the global secondary index b. When the data node of the global secondary index b deletes the data row, it cannot find this tuple. Similarly, at this time, the present application provides a data processing method, such as Fig.11 shown.
[0328] In this data processing method, the data node can obtain the data information of the deleted row from the WHERE deletion condition of the SQL statement "DELETE FROM b WHERE cashierid=$3 AND counterid=$1 AND fno=$2 AND location information=$4 AND version information=$5", which contains the data content of all columns corresponding to the deleted row. This data information can be used to fill in the overall data of the tuple to be deleted (MNG695478, 3, 2, location information, version information). The pieced-to-be-deleted tuple is first inserted into the global secondary index b, and then the tuple is deleted immediately. At this time, the deletion effect of the tuple (MNG695478, 3, 2, location information, version information) can be presented in the global secondary index b.
[0329] Correspondingly, if Fig.12 As shown, the data filling process of creating GSI online subsequently obtains the visible data in the data table B based on the snapshot, and the above-mentioned deleted tuple (3, 2, MNG695478) can be scanned. Therefore, when the corresponding data node wants to insert the corresponding tuple (MNG695478, 3, 2, location information, version information) into the global secondary index b, at this time, according to its index key (cashier ID) in the global secondary index b, the storage location with the same index key can be quickly located. After scanning and comparison, it is found that the global secondary index b already has rows (MNG695478, 3, 2, location information, version information) with the same data content in all columns (distribution key, index key and additional key, location information, version information), then the insertion is skipped and returned directly.
[0330] In this way, after the global secondary index b is created, if the data row in table B is deleted during the creation of the global secondary index b, the global secondary index b will also delete the data row accordingly, and the data will remain consistent.
[0331] In another scenario, after data table B processes the UPDATE operation to update a row of data (tuple), the data node of the global secondary index b can update the corresponding data row in the global secondary index a. As an example, take the data table B as an example to update the tuple (3, 2, MNG695478) to (3, 10, MNG695478) with fno=2 as the condition. The tuple update operation on data table A can be performed through the SQL statement: "UPDATE B SET fno=10 WHERE fno=2 RETURNING counterid_new, fno_new, cashierid_new, location information_new, version information_new, counterid, fno, cashierid, location information, version information". The meaning of this statement is to update the tuple (3, 2, MNG695478) to (3, 10, MNG695478) according to the update condition, and return the data content before and after the update on all columns, including cashier ID, number of mall floors, cashier ID, location information and version information. The SQL statement can be broadcasted by the coordinating node 2 to all data nodes to attempt to delete it, because its deletion condition does not contain the distribution key.
[0332] Then, the data update operation on the global secondary index b can be performed through the SQL statement: "UPDATE b SETcashierid=$3, counterid=$1 AND fno=$3 location information=$4 AND version information=$5 WHEREcashierid=$8 AND counterid=$6 AND fno3=7 AND location information=$9 AND version information=$10". The meaning of this statement is to extract the required cashier ID, cashier counter ID, shopping mall floor number, location information and version information from the above returned data content as update conditions, and update the corresponding tuple (MNG695478, 3, 2, location information, version information) in the global secondary index b to (MNG695478, 3, 10, location information_new, version information_new). Its SQL statement is calculated by the coordination node 2 or the data node that executes the update operation of the data table B and sent to the corresponding data node according to the cashier ID range distribution algorithm to perform the update operation.
[0333] When the data node performs the corresponding data update on the global secondary index b, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. That is, first delete the old tuple (MNG695478, 3, 2, location information, version information), and then insert the new tuple (MNG695478, 3, 10, location information, version information). It should be noted that when deleting the old tuple, the above-mentioned DELETE operation situation 2 may occur, that is, the situation where the corresponding tuple cannot be found in the global secondary index b. The corresponding processing method is the same as above and will not be repeated.
[0334] After the global secondary index b is created, the data row in table B that is updated during the creation of the global secondary index b is also updated by the global secondary index b accordingly, and the data remains consistent.
[0335] Finally, coordination node 1 notifies and waits for all nodes to complete the metadata update of the global secondary index b and commits transaction two. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 generates the metadata version modification command ALTER INDEX{b}GSIVAILD and sends it to all nodes. The metadata version modification can be achieved by setting the status flag indisvalid corresponding to the global secondary index b in the system table to TRUE. And wait for each node to complete the modification of the metadata version. Coordination node 1 commits transaction two, and the metadata version of the global secondary index b is now globally unified. The creation of the global secondary index b is completed.
[0336] Since the global secondary index b is a data structure sorted by the index key cashierid defined by the user, when the user queries based on cashierid, the desired data can be quickly queried based on the global secondary index b.
[0337] As another example, the index creation method provided in this application can also be applied to a product sales system of an e-commerce company based on a distributed system architecture. For example, there is a data table in the product sales system. The table name of the data table is C, and the attribute columns include: sales_id sales record ID; saleman salesperson; saledate sales time; city sales city (distribution key). The data of the entire data table C is shown in Table 3:
[0338] Table 3
[0339] sales_id saleman saledate city 1 Alan 2023-06-02-10-11 Beijing 2 Bob 2023-06-02-11-23 Shenzhen 3 Cathy 2023-06-02-11-42 Shanghai 4 Bob 2023-06-02-14-55 Shenzhen 5 Tom 2023-06-02-15-02 Hangzhou … … … …
[0340] Among them, city is the distribution key. Since the product is only sold in a few fixed cities, data table C uses list distribution. In particular, the sales staff is also within a fixed range of staff.
[0341] When a user inputs a request to create a global secondary index on data table C, a coordination node (server or virtual machine on the server) in the product sales system can receive the request and be responsible for creating the global secondary index of data table C. The following example describes this solution by taking the example of a user creating a global secondary index c on data table C, with the attributes of the global secondary index c being saleman salesperson (index key, distribution key); saledate sales time (additional key); and sales_id sales record ID (additional key).
[0342] The statement to create a global secondary index c can be: "CREATE GLOBAL INDEX CONCURRENTLY con C(saleman) CONTAINING(saledate, sales_id) DISTRIBUTE BY LIST(saleman)", where CREATE GLOBAL INDEX means to create a global secondary index, CONTAINING means additional key, and DISTRIBUTE BY LIST means to distribute in list mode. The meaning of this statement is: on the data table C with the distribution key of sales record ID, create a global secondary index c with the index key and distribution key of salesperson, the distribution mode of list distribution, the additional key of sales time, and the sales record ID.
[0343] First, a request for creating a global secondary index input by a user is sent to a coordination node in the product sales system. This coordination node may be responsible for creating coordination node 1 of the global secondary index C.
[0344] Then the coordination node 1 starts transaction one, notifies and waits for all nodes to complete the initialization of the global secondary index c before submitting transaction one. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 notifies and waits for each node to initialize the metadata of the global secondary index c and sets the version to writable but not readable (write only), and submits transaction one. The setting of writable but not readable (write only) can be achieved by setting the status flag (indisvalid) corresponding to the global secondary index c in the system table to FALSE. During the entire process of creating and initializing the global secondary index c, a SHARE LOCK can be added to the data table C. The metadata version of the global secondary index c is now globally unified.
[0345] Next, coordination node 1 starts transaction 2, notifies and waits for all nodes to complete waiting for all currently active transactions. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 generates a waiting command ALTER TABLE{C}GSIWAITALL. Among them, waiting for all DML transactions to be implemented can be completed by waiting for transactions that conflict with obtaining the SHARELOCK lock on data table C. Then add a SHARE UPDATE EXCLUSIVE LOCK to data table C. Coordination node 1 sends commands to all nodes, and waits for each node to complete waiting for the current active transaction to end, and then adds a SHARE UPDATE EXCLUSIVE LOCK to data table C. Alternatively, as another case, coordination node 1 can also wait for all nodes to complete active transactions first, and then uniformly add a SHARE UPDATE EXCLUSIVE LOCK to each node.
[0346] Then, coordination node 1 organizes the data of data table C to fill in the global secondary index c. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 can first add a ROW EXCLUSIVELOCK lock to the global secondary index c. Here, the row exclusive lock is used to achieve non-blocking IUD operations on the global secondary index c but blocking other operations, such as DDL operations. Then coordination node 1 obtains the current snapshot and starts to organize the acquisition of the data required for the global secondary index c (distribution key, index key, and additional key corresponding columns) from the data table C under the snapshot and fill it into the global secondary index b.
[0347] The data can be filled in through the SQL statement: "INSERT INTO c(saleman, soldate, sales_id, location information, version information) SELECT saleman, soldate, sales_id, location information, version information FROM C". This statement means selecting the salesperson, sales date, sales record ID, location information and version information from the data table C and inserting them into the global secondary index c. The location information is used to indicate the location of the data in the data table, such as the node information (xc_node_hash) where the data is located and the storage location (ctid) in the node. The data node where the data should be inserted is obtained by the value of the distribution key saleman of the global secondary index c under the list distribution algorithm.
[0348] When the coordination node 1 confirms that all the data under the snapshot has been scanned and filled into the global secondary index c, the filling is completed.
[0349] Similarly, during the filling process of the data nodes of the global secondary index c, the data modifications caused by the IUD operation that occurs synchronously in the data table C need to be reflected in the global secondary index c accordingly to ensure the consistency of the data after the creation is completed. For example, during the data filling process, when the same user or other users input an IUD operation request on the data table C, the IUD operation request will also be sent to a coordination node 2 in the product sales system. Optionally, coordination node 2 and coordination node 1 can be the same or different. Coordination node 2 can issue a command to the corresponding data node based on the IUD operation request, and the corresponding data node will perform IUD processing on the data. At this time, a data node may need to synchronously perform data filling and IUD processing on the global secondary index c.
[0350] In one scenario, after data table C processes an INSERT operation to insert a new row of data (tuple), the data node of the global secondary index c can obtain the data required by the global secondary index c (columns corresponding to the distribution key, index key, and additional key) and insert it into the global secondary index c. As an example, take the insertion of the data tuple (2, Bob, 2023-06-02-11-23, Shenzhen) into data table C. The data tuple insertion operation into data table C can be performed through the SQL statement: "INSERT INTOC (sales_id, saleman, soldate, city) VALUES (2, Bob, 2023-06-02-11-23, Shenzhen) RETURNING sales_id, saleman, soldate, city, location information, version information". This statement means inserting the tuple to be inserted (2, Bob, 2023-06-02-11-23, Shenzhen) and returning the data content of all columns of the tuple, including salesperson, sales time, sales city, location information and version information. The SQL statement can be calculated by the coordination node 2 according to the distribution key sales city list distribution algorithm and sent to the corresponding data node for execution.
[0351] Then, the tuple insertion of the global secondary index c can be performed through the SQL statement: "INSERT INTO c(saleman, soldate, sale_id, location information, version information) VALUES ($2, $3, $1, location information, version information)". The meaning of this statement is to extract the required salesperson, sales date, sales record ID, location information and version information from the above returned data content, and form a tuple to be inserted into the global secondary index c. The SQL statement is calculated by the coordination node 2 or the data node that executes the insert operation of the data table C according to the distribution algorithm of the distribution key salesperson list and sent to the corresponding data node for execution. After the global secondary index c is created, the tuples newly added in the data table C during the creation of the global secondary index c also have corresponding tuples in the global secondary index c, and the data remains consistent.
[0352] In another scenario, after data table C processes a DELETE operation to delete a row of old data (tuple), the data node of the global secondary index c can delete the corresponding data row in the global secondary index c. Take the case of deleting the tuple (2, Bob, 2023-06-02-11-23, Shenzhen) from data table C with saledate=2023-06-02-11-23 as the condition. As an example, the tuple deletion operation on data table C can be performed through the SQL statement: "DELETE FROM C WHERE saledate=2023-06-02-11-23 RETURNING sales_id, saleman, saledate, city, location information, version information". The meaning of this statement is to delete the tuple (2, Bob, 2023-06-02-11-23, Shenzhen) according to the deletion condition, and return the data content on all columns, including salesperson, sales time, sales city, location information and version information. The SQL statement can be broadcasted by coordinating node 2 to all data nodes to attempt to delete, because its deletion condition does not contain the distribution key;
[0353] Then, the data deletion operation on the global secondary index c can be performed through the SQL statement: "DELETE FROM c WHEREsaleman=$2AND saledate=$3 AND saleid=$1 AND location information=$5 AND version information=$6". The meaning of this statement is to extract the required salesperson, sales date, sales record ID, location information and version information from the above returned data content as the deletion condition, and delete the corresponding tuple (Bob, 2023-06-02-11-23, 2, location information, version information) in the global secondary index c. Its SQL statement is calculated by the coordination node 2 or the data node that executes the deletion operation of the data table C according to the distribution key salesperson list distribution algorithm and sent to the corresponding data node to perform the deletion operation.
[0354] Similarly, when the data node of the global secondary index c receives an SQL request to delete the tuple (Bob, 2023-06-02-11-23, 2, location information, version information), the following two situations may occur:
[0355] Case 1: The tuple (Bob, 2023-06-02-11-23, 2, location information, version information) has been processed by the data filling process of online GSI creation and filled into the global secondary index c. When the data node of the global secondary index c deletes the data row, this tuple can be found in the data of the global secondary index c, and the deletion is performed normally.
[0356] Case 2: The tuple (Bob, 2023-06-02-11-23, 2, location information, version information) has not been processed by the data filling process of creating GSI online, and has not been filled into the global secondary index c. The data node of the global secondary index c cannot find this tuple when it is deleted. Similarly, this application provides a data processing method, such as Fig.11 shown.
[0357] In this data processing method, the data information of the deleted row is obtained from the WHERE deletion condition of the SQL statement "DELETE FROM c WHERE saleman=$2 ANDsaledate=$3 AND saleid=$1 AND location information=$5 AND version information=$6", which contains the data content of all columns corresponding to the deleted row. This data information can be used to fill in the overall data of the tuple to be deleted (Bob, 2023-06-02-11-23, 2, location information, version information). The pieced-to-be-deleted tuple is first inserted into the global secondary index c, and then the tuple is deleted immediately. At this time, the deletion effect of the tuple (Bob, 2023-06-02-11-23, 2, location information, version information) can be presented in the global secondary index c.
[0358] Correspondingly, if Fig.12 As shown, the data filling process of creating GSI online subsequently obtains the visible data in the data table C based on the snapshot, and the above-mentioned deleted tuple (2, Bob, 2023-06-02-11-23, Shenzhen) can be scanned. Therefore, when the corresponding data node wants to insert the corresponding tuple (Bob, 2023-06-02-11-23, 2, location information, version information) into the global secondary index c, at this time, according to its index key (salesperson), the storage location with the same index key can be quickly located in the global secondary index c. After scanning and comparison, it is found that the global secondary index c already has rows (Bob, 2023-06-02-11-23, 2, location information, version information) with the same data content in all columns (distribution key, index key and additional key, location information, version information), then the insertion is skipped and returned directly.
[0359] After the global secondary index c is created, if the data row in table C is deleted during the creation of the global secondary index c, the global secondary index also deletes the data row accordingly, and the data remains consistent.
[0360] In another scenario, after data table C processes an UPDATE operation to update a row of data (tuple), the data node of the global secondary index c can update the corresponding data row in the global secondary index c. As an example, take the data table C with city=Shanghai as the condition to update the tuple (3, Cathy, 2023-06-02-11-42, Shanghai) to (5, Cathy, 2023-06-02-11-42, Shanghai). The tuple update of data table A can be done through the SQL statement: "UPDATE C SET slae_id=5WHERE city=Shanghai RETURNING sale_id_new, slaeman_new, saledata_new, city_new, location information_new, version information_new, sale_id, saleman, saledata, city, location information, version information". The meaning of this statement is to update the tuple (3, Cathy, 2023-06-02-11-42, Shanghai) to (5, Cathy, 2023-06-02-11-42, Shanghai) according to the update condition, and return the data content before and after the update on all columns, including salesperson, sales time, sales city, location information and version information. Its SQL statement can be calculated by the coordination node 2 according to the distribution key sales city list distribution algorithm and sent to the corresponding data node for execution.
[0361] Then, the data update operation on the global secondary index c can be performed through the SQL statement: "UPDATE c SET saleman=$2, soldate=$3, sale_id=$3, location information=$5, version information=$6 WHERE saleman=$8 AND soldate=$9 AND sale_id=7 AND location information=$11 AND version information=$12". The meaning of this statement is to extract the required salesperson, sales date, sales record ID, location information and version information from the above returned data content as update conditions, and update the corresponding tuple (Cathy, 2023-06-02-11-42, 3, location information, version information) in the global secondary index c to (Cathy, 2023-06-02-11-42, 5, location information_new, version information_new). Its SQL statement is calculated by the coordination node 2 or the data node that executes the update operation of the data table C, and is sent to the corresponding data node according to the salesperson list distribution algorithm to perform the update operation.
[0362] When the data node performs the corresponding data update on the global secondary index c, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. That is, first delete the old tuple (Cathy, 2023-06-02-11-42, 3, location information, version information), and then insert the new tuple (Cathy, 2023-06-02-11-42, 5, location information_new, version information_new). It should be noted that when deleting the old tuple, the above-mentioned DELETE operation situation 2 may occur, that is, the corresponding tuple cannot be found in the global secondary index c. The corresponding processing is the same as above and will not be repeated.
[0363] After the global secondary index c is created, the data row in the data table C that is updated during the creation of the global secondary index c is also updated accordingly by the global secondary index c, and the data remains consistent.
[0364] Finally, coordination node 1 notifies and waits for all nodes to complete the metadata update of the global secondary index c and commits transaction two. In this step, it is basically consistent with the execution logic of the aforementioned student registration system. Coordination node 1 generates the metadata version modification command ALTER INDEX{c}GSIVAILD and sends it to all nodes. And wait for each node to complete the modification of the metadata version. Coordination node 1 commits transaction two, and the metadata version of the global secondary index c is now globally unified. The creation of the global secondary index c is completed.
[0365] Since the global secondary index c is a data structure sorted by the user-defined index key saleman, when the user queries based on the saleman field, the desired data can be quickly queried based on the global secondary index c.
[0366] As another example, the index creation method provided by this application can be applied to a student file system based on a distributed system architecture. For example, the student file system has a data table. The table name of the data table is D, and the attribute columns include: studentid student ID (distribution key); docid file ID (partition key), name student name, classid class ID. The data of the entire data table D is shown in Table 4:
[0367] Table 4
[0368] StudentID docid name classid 1 100101 Xiao Ming 11 2 500132 Xiao Wang 12 3 200177 Xiao Zhang 13 4 200211 Xiao Li 9 5 300223 Xiao Yang 8 6 400154 Little Red 7 … … …
[0369] Among them, studentid is an auto-incrementing and unique attribute, so data table D adopts hash distribution, and distributes data relatively evenly to each node of the distributed system through the hash algorithm and according to the studentid column. At the same time, on each node, the data is partitioned and stored according to the value of the partition key docid. That is, data table D is stored in the data node according to the hash algorithm of the studentid column, and is further partitioned and stored on the data node according to the partition key docid. For example, if the value is less than 300,000, there is one partition, and if it is greater than or equal to 300,000, there is another partition. Fig.13 As shown, in data node 1 (containing data of studentid[1, 2, ...]), tuple (1, 100101, Xiaoming, 11) is stored in partition 1, and tuple (2, 500132, Xiaowang, 12) is stored in partition 2. In data node 2 (containing data of studentid[3, 4, ...]), tuple (3, 200177, Xiaozhang, 13) and tuple (4, 200211, Xiaoli, 9) are stored in partition 1.
[0370] When a user inputs a request to create a global secondary index on data table D, a coordination node (a server or a virtual machine on the server) in the archive system can receive the request and be responsible for creating the global secondary index of data table D.
[0371] The following example introduces this solution by taking the case where a user creates a global secondary index d on table D, where the attributes of the global secondary index d are: classid class ID (index key and distribution key); docid file ID (additional key); name student name (additional key).
[0372] The statement for creating a global secondary index d can be: "CREATE GLOBAL INDEX CONCURRENTLY don D(classid) CONTAINING(docid, name) DISTRIBUTE BY Hash(classid)", where CREATE GLOBAL INDEX means creating a global secondary index, CONTAINING means additional key, and DISTRIBUTE BY HASH means distribution in hash distribution mode. The meaning of this statement is: on data table D with distribution key as class ID, create a global secondary index d with index key and distribution key as class ID, distribution mode as hash distribution, additional key as student name and file ID.
[0373] First, a request for creating a global secondary index input by a user is sent to a coordination node in the archive system, and this coordination node may be the coordination node 1 responsible for creating the global secondary index d.
[0374] Then the coordination node 1 starts transaction one, notifies all nodes waiting to complete the initialization of the global secondary index d and then commits transaction one. In this step, the coordination node 1 sends a creation instruction to all other coordination nodes and data nodes. Each other coordination node and data node initializes the metadata of the global secondary index d and sets the metadata version to writable but not readable (write only), and then feeds back to the coordination node 1 for processing. Among them, the setting of writable but not readable (write only) can be achieved by setting the status flag (indisvalid) corresponding to the global secondary index d in the system table to FALSE. During the entire process of creating and initializing the global secondary index d, a shared (SHARE LOCK) lock can be added to the data table D. The SHARELOCK lock can also be called a read lock, which is used to block other operations except query operations, such as IUD operations, in order to ensure that the data in the data table D remains unchanged.
[0375] After coordinating node 1 confirms that it has received feedback from all other nodes that the above operations have been completed, coordinating node 1 creates and initializes the metadata of global secondary index d and sets the metadata version to writable but not readable (write only), and in this process, a SHARE LOCK can be added to data table D. Coordinating node 1 commits transaction 1, and the metadata version of global secondary index d is now globally unified.
[0376] Next, coordination node 1 starts transaction 2, notifies and waits for all nodes to complete waiting for all currently active transactions. In this step, coordination node 1 generates a wait command and sends it to all other coordination nodes and data nodes. The wait command can be an SQL statement: ALTER TABLE{D}GSIWAITALL. Each node executes the command and waits for all currently active DML transactions on data table D to end. Among them, waiting for all DML transactions can be achieved by waiting for transactions that conflict with the SHARE LOCK lock on data table D to complete. The transactions that conflict with the SHARE LOCK lock here can be understood as other operations other than the query operation blocked above, such as IUD operations. After waiting is completed, a shared update exclusive (SHAREUPDATE EXCLUSIVE LOCK) lock is added to data table D, so as not to block the read operation and DML operation of data table D. Then feedback is given to coordination node 1 to process the completion of the above operations. After coordinating node 1 confirms that it has received feedback from all other nodes that the above operations have been completed, coordinating node 1 waits for all currently active DML transactions on its own node on data table D to end, and adds a SHAREUPDATE EXCLUSIVE LOCK to data table D. Alternatively, as another case, coordinating node 1 first waits for all nodes to complete active transactions, and then the coordinating node locks each node.
[0377] Then, the coordination node 1 organizes the data of the data table D to be filled into the global secondary index d. In this step, the coordination node 1 first adds a row exclusive lock (ROW EXCLUSIVE LOCK) to the global secondary index d. Here, the row exclusive lock is used to achieve non-blocking IUD operations on the global secondary index d but blocking other operations, such as DDL operations. Then the coordination node 1 obtains the current snapshot, and starts to organize the acquisition of the data required for the global secondary index d (the columns corresponding to the distribution key, index key, and additional key) from the data table D under the snapshot and fills it into the global secondary index d. The data can be filled through the SQL statement: "INSERT INTO d(classid, docid, name, location information, version information, partition information) SELECT classid, docid, name, location information, version information, partition information FROM A". This statement means selecting the class ID, file ID, student name, location information, version information, and partition information from the data table D and inserting them into the global secondary index d. The location information is used to indicate the location of the data in the data table, including the node information (xc_node_hash) where the data is located and the storage location (ctid) in the node. The partition information indicates the partition location of the data in the data table, including the partition information (tableoid) in the node where the data is located. The data node where the data should be inserted is derived from the value of the global secondary index d distribution key classid under the hash algorithm.
[0378] When the coordinating node 1 confirms that all the data under the snapshot has been scanned and filled into the global secondary index d, the filling is completed.
[0379] Similarly, during the filling process of the data nodes of the global secondary index d, the data modifications caused by the IUD operation that occurs synchronously in the data table D must also be reflected in the global secondary index d accordingly to ensure the consistency of the data after the creation is completed. For example, during the data filling process, when the same user or other users input an IUD operation request on the data table D, the IUD operation request will also be sent to a coordination node 2 in the student archive system. Optionally, coordination node 2 and coordination node 1 can be the same or different. Coordination node 2 can issue a command to the corresponding data node based on the IUD operation request, and the corresponding data node will perform IUD processing on the data. At this time, a data node may need to synchronously perform data filling and IUD processing on the global secondary index c.
[0380] In one scenario, after data table D processes an INSERT operation to insert a new row of data (tuple), the data node of the global secondary index d can obtain the data required by the global secondary index d (distribution key, index key, and additional key) and insert it into the global secondary index d. Take the insertion of the data tuple (2, 500132, Xiao Wang, 12) into data table D as an example. The data tuple insertion operation into data table D can be performed through the SQL statement: "INSERT INTO D (studentid, docid, name, classid) VALUES (2, 500132, Xiao Wang, 12) RETURNING studentid, docid, name, classid, location information, version information, partition information". The meaning of this statement is to insert the tuple to be inserted (2, 500132, Xiao Wang, 12) and return the data content on all columns of the tuple, including class ID, student name, student ID, location information, version information, and partition information. The SQL statement can be calculated by the coordination node 2 according to the distribution key student ID hash algorithm and sent to the corresponding data node for execution;
[0381] Then, the tuple insertion of the global secondary index d can be carried out through the SQL statement: "INSERT INTO d(classid, docid, name, location information, version information, partition information) VALUES($4, $2, $3, $5, $6, $7)". The meaning of this statement is to extract the required class ID, file ID, student name, location information, version information and partition information from the above returned data content, and form a tuple to be inserted into the global secondary index d. The SQL statement is calculated by the coordination node 2 or the data node that executes the insertion operation of the data table D according to the distribution key class ID hash algorithm and sent to the corresponding data node for execution. After the global secondary index d is created, the tuples newly added in the data table D during the creation process of the global secondary index d also have corresponding tuples in the global secondary index d, and the data remains consistent.
[0382] In another scenario, after data table D processes a DELETE operation to delete a row of old data (tuple), the data node of the global secondary index d can delete the corresponding data row in the global secondary index d. As an example, take the data table D as an example to delete the tuple (2, 500132, Xiao Wang, 12) with the condition of studentid=2. The tuple deletion operation on data table D can be performed through the SQL statement: "DELETE FROM D WHERE studentid=2 RETURNING studentid, docid, name, classid, location information, version information, partition information". The meaning of this statement is to delete the tuple (2, 500132, Xiao Wang, 12) according to the deletion condition, and return the data content on all columns, including class ID, student name, student ID, location information, version information and partition information. Since the deletion condition for data table D includes the distribution key (student ID), the SQL statement can be calculated by the coordination node 1 according to the distribution key student ID hash algorithm and sent to the corresponding data node for execution;
[0383] Then, the data deletion operation on the global secondary index d can be performed through the SQL statement: "DELETE FROM d WHEREclassid=$4 AND docid=$2 AND name=$3 AND location information=$5 AND version information=$6 AND partition information=$7". The meaning of this statement is to extract the required class ID, student name, location information, version information and partition information from the above returned data content as the deletion conditions, and delete the corresponding tuple (12, 500132, Xiao Wang, location information, version information, partition information) in the global secondary index d. The SQL statement is sent to the corresponding data node by the coordination node 2 or the data node that executes the deletion operation of the data table D according to the distribution key class ID hash algorithm to perform the deletion operation.
[0384] Similarly, when the data node of the global secondary index d receives an SQL request to delete the tuple (12, 500132, Xiao Wang, location information, version information, partition information), the following two situations may occur:
[0385] Case 1: The tuple (12, 500132, Xiao Wang, location information, version information, partition information) has been processed by the data filling process of online GSI creation and filled into the global secondary index d. When the data node of the global secondary index d deletes the data row, this tuple can be found in the data of the global secondary index d, and the deletion is performed normally.
[0386] Case 2: The tuple (12, 500132, Xiao Wang, location information, version information, partition information) has not been processed by the data filling process for creating GSI online, and has not been filled into the global secondary index d. When the data node of the global secondary index d performs data row deletion processing, this tuple cannot be found. Similarly, an embodiment of the present application provides a data processing method.
[0387] In this data processing method, the data information of the deleted row is obtained from the WHERE deletion condition of the SQL statement "DELETE FROM d WHERE classid=$4AND docid=$2 AND name=$3 AND location information=$5 AND version information=$6 AND partition information=$7", which contains the data content of all columns corresponding to the deleted row. This data information can be used to fill in and piece together the overall data of the tuple to be deleted (12, 500132, Xiao Wang, location information, version information, partition information). The pieced-to-be-deleted tuple is first inserted into the global secondary index d, and then the tuple is deleted immediately. At this time, the deletion effect of the tuple (12, 500132, Xiao Wang, location information, version information, partition information) can be presented in the global secondary index d.
[0388] Correspondingly, the online creation of the GSI data filling process subsequently obtains the visible data in the data table D based on the snapshot, and can scan the tuple (2, 500132, Xiao Wang, 12). Therefore, when the corresponding data node wants to insert the corresponding tuple (12, 500132, Xiao Wang, location information, version information, partition information) into the global secondary index d, at this time, according to its index key (class ID), the storage location with the same index key can be quickly located in the global secondary index d. After scanning and comparison, it is found that the global secondary index d already has rows (12, 500132, Xiao Wang, location information, version information, partition information) with the same data content in all columns (distribution key, index key and additional key, location information, version information, partition information), then the insertion is skipped and returned directly.
[0389] After the global secondary index d is created, if the data row in table D is deleted during the creation of the global secondary index d, the global secondary index d will also delete the data row accordingly, and the data will remain consistent.
[0390] In another scenario, after data table D processes an UPDATE operation to update a row of data (tuple), the data node of the global secondary index d can update the corresponding data row in the global secondary index d. As an example, take data table D with studentid=12 as the condition to update the tuple (2, 500132, Xiao Wang, 12) to (2, 500132, Xiao Li, 12). The tuple update operation on data table D can be performed through the SQL statement: "UPDATE D SET name="Xiao Li" WHERE studentid=12RETURNING student_new, docid_new, name_new, classid_new, location information_new, version information_new, partition information_new, student, docid, name, classid, location information, version information, partition information". The meaning of this statement is to update the tuple (2, 500132, Xiao Wang, 12) to (2, 500132, Xiao Li, 12) according to the update condition, and return the data content before and after the update on all columns, including class ID, student name, student ID, location information, version information and partition information. The SQL statement can be calculated by the coordination node 2 according to the distribution key student ID hash algorithm and sent to the corresponding data node for execution;
[0391] Then, the data update operation of the global secondary index d can be performed through the SQL statement: "UPDATE d SET classid=$4AND docid=$2 AND name=$3 AND location information=$5 AND version information=$6 AND partition information=$7WHERE classid=$11 AND docid=$9 AND name=$10 AND location information=$12 AND version information=$13 AND partition information=$14". The meaning of this statement is to extract the required class ID, file ID, student name, location information, version information and partition information from the above returned data content as update conditions, and update the corresponding tuple (12, 500132, Xiao Wang, location information, version information, partition information) in the global secondary index d to (12, 500132, Xiao Li, location information, location information_new, version information_new, partition information_new). Its SQL statement is sent by the coordination node 2 or the data node that executes the update operation of the data table D to the corresponding data node to perform the update operation according to the distribution key class ID hash algorithm.
[0392] When the data node performs corresponding data updates on the global secondary index d, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. That is, first delete the old tuple (12, 500132, Xiao Wang, location information, version information, partition information), and then insert the new tuple (12, 500132, Xiao Li, location information, location information_new, version information_new, partition information_new). In particular, when deleting the old tuple, the above-mentioned DELETE operation situation 2 may occur, that is, the situation where the corresponding tuple cannot be found in the global secondary index d. The corresponding processing method is the same as above and will not be repeated.
[0393] After the global secondary index d is created, the data row in the data table D that is updated during the creation of the global secondary index d is also updated accordingly by the global secondary index d, and the data remains consistent.
[0394] Finally, coordination node 1 notifies and waits for all nodes to complete the metadata update of the global secondary index d, and commits transaction two. In this step, coordination node 1 generates a metadata version modification command and sends it to all other coordination nodes and data nodes. The metadata version modification command can be an SQL statement ALTER INDEX{d}GSIVAILD. Each node executes the command, sets the metadata version to available (public), and then feeds back to coordination node 1 for processing. The setting of the available (public) version can be achieved by setting the status flag (indisvalid) corresponding to the global secondary index d on the system table to TRUE. After coordinating node 1 confirms the feedback from all other nodes, it sets its own metadata version to public. Coordinating node 1 commits transaction two, and the metadata version of the global secondary index d is now globally unified. The creation of the global secondary index d is completed.
[0395] For example, after the online creation of the global secondary index d on the data table D is completed, the data distribution of the global secondary index d in the distributed system can be as follows: Fig.14 As shown. The global secondary index d is sharded into shard 1 of the global secondary index d (including data of classid[13, 12, ...]), shard 2 of the global secondary index d (including data of classid[11, 9, ...]), and shard 3 of the global secondary index d (including data of classid[8, 7, ...]). Shard 1 of the global secondary index d is stored in data node 1, shard 2 of the global secondary index d is stored in data node 2, and shard 3 of the global secondary index d is stored in data node 3.
[0396] like Fig.13As shown in the figure, the shards of the global secondary index d are all data structures sorted by the index key classid defined by the user. In this way, when the user queries based on classid, the desired data can be quickly queried based on the global secondary index d.
[0397] The embodiment of the present application provides an index creation method. In the process of creating a global secondary index online in a distributed system, the coordination node needs to notify and wait for all nodes to complete the metadata update before starting to update the metadata of its own node, thereby realizing the global consistency under the metadata non-asynchronous (synchronous) update mechanism. In this way, the high concurrency performance of the distributed system can be guaranteed, and the third-party node / tool that has already borne the high concurrent access load is not introduced to coordinate the asynchronous update of metadata. The high availability of the distributed system is also guaranteed. The coordination node needs to wait until all nodes have normal feedback before continuing the process, and does not hinder the normal execution of user DML transactions. And the architecture design is simple, the cost is low, and the third-party node / tool is not introduced to coordinate metadata updates. And due to the solution provided by the present application, in the process of creating a global secondary index online in a distributed system, the coordination node needs to notify and wait for all nodes to wait for the current active transaction to complete before starting to fill the index data. While ensuring data consistency, since the coordination node waits until all nodes have normal feedback to continue the process, it does not hinder the normal execution of user DML transactions, and thus also guarantees high availability.
[0398] It is understandable that, in order to implement the above functions, the coordination node includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and software. Whether a function is executed in a hardware or software-driven hardware manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.
[0399] In this embodiment, the functional modules of the coordination node can be divided according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0400] The present application also provides an index creation device in a distributed system, which can be applied to any coordination node in the distributed system. The device is used to execute the various functions or steps executed by the coordination node in the above method embodiment.
[0401] The embodiment of the present application further provides a coordination node in a distributed system, the coordination node comprising the above index creation device. Optionally, the coordination node can be an independent server or a virtual machine in the server.
[0402] The embodiment of the present application also provides a chip system, which includes a processor and at least one interface circuit. The processor and the interface circuit can be interconnected through a line. The interface circuit can read the instructions stored in the memory and send the instructions to the processor. When the instructions are executed by the processor, the chip system can perform the various functions or steps performed by the coordination node in the above method embodiment. Of course, the chip system can also include other discrete devices, which is not specifically limited in the embodiment of the present application.
[0403] An embodiment of the present application also provides a storage medium, which includes instructions. When the instructions are executed on the above-mentioned index creation device, the index creation device executes each function or step executed by the coordinating node in the above-mentioned method embodiment.
[0404] Among them, the index creation device, coordination node, storage medium or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0405] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0406] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0407] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0408] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0409] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0410] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A method for creating an index in a distributed system, characterized in that: Applied to a coordination node in the distributed system, the distributed system further comprising a plurality of other nodes, the method comprising: In the online creation process of the global secondary index GSI, notifying the multiple other nodes to configure metadata of the global secondary index, wherein the metadata includes a metadata version, and the configuration is used to update and / or generate the metadata; When the coordination node meets a preset condition, metadata of the global secondary index is configured on the coordination node.
2. The method according to claim 1, characterized in that The preset condition includes receiving completion feedback information returned by each of the multiple other nodes.
3. The method according to claim 1 or 2, characterized in that: The distributed system also includes a client, and in the process of online creation of the global secondary index, notifying the multiple other nodes to generate metadata of the global secondary index includes: Receiving an index creation request from the client, where the index creation request is used to instruct online creation of a global secondary index; In response to the index creation request, informing the multiple other nodes to create and initialize metadata of the global secondary index, and setting the metadata version in the metadata to the first version; When the coordinating node meets a preset condition, generating metadata of the global secondary index on the coordinating node includes: When the coordinating node meets a preset condition, metadata of the global secondary index is created and initialized on the coordinating node, and the metadata version in the metadata is set to the first version.
4. The method according to claim 1 or 2, characterized in that: In the online creation process of the global secondary index, notifying the multiple other nodes to update the metadata of the global secondary index includes: When the coordinating node and the multiple other nodes have completed setting the first version of the metadata version in the metadata of the global secondary index, notifying the multiple other nodes to update the metadata version from the first version to the second version; When the coordinating node meets a preset condition, updating the metadata of the global secondary index on the coordinating node includes: When the coordination node meets a preset condition, the metadata version is updated from the first version to the second version on the coordination node.
5. The method according to claim 1 or 2, characterized in that: The global secondary index is associated with a field on a data table, and in the online creation process of the global secondary index, notifying the multiple other nodes to update metadata of the global secondary index includes: When the coordination node and the plurality of other nodes complete setting of the first version of the metadata version in the metadata of the global secondary index, filling the relevant data in the data table into the global secondary index; When the data filling of the global secondary index is completed, notifying the multiple other nodes to update the metadata version from the first version to the second version; When the coordinating node meets a preset condition, updating the metadata of the global secondary index on the coordinating node includes: When the coordination node meets a preset condition, the metadata version is updated from the first version to the second version on the coordination node.
6. The method according to claim 4 or 5, characterized in that: The global secondary index is associated with a field on the data table. After the coordination node and the multiple other nodes complete setting of a first version of a metadata version in the metadata of the global secondary index, the method further includes: Wait for all transactions of the data table on the coordinating node and the multiple other nodes to be completed.
7. The method according to claim 1 or 2, characterized in that: The distributed system also includes a client, the preset condition includes a first preset condition and a second preset condition, and in the online creation process of the global secondary index, notifying the multiple other nodes to configure the metadata of the global secondary index, and configuring the metadata of the global secondary index on the coordinating node when the coordinating node meets the preset condition, includes: Receiving an index creation request from the client, wherein the index creation request is used to instruct online creation of a global secondary index associated with a field on a data table; In response to the index creation request, notify the multiple other nodes to create and initialize metadata of the global secondary index, and set the metadata version in the metadata to a first version, where the first version is used to indicate that the global secondary index is writable but not readable; When the coordinating node satisfies the first preset condition, metadata of the global secondary index is created and initialized on the coordinating node, and the metadata version in the metadata is set to the first version, wherein the first preset condition includes receiving setting feedback information returned by each of the multiple other nodes, and the setting feedback information is used to indicate that creation and initialization of the metadata have been completed, and setting of the first version has been completed; After waiting for all transactions of the data table on the coordinating node and the multiple other nodes to be completed, fill the relevant data in the data table into the global secondary index; When the data filling of the global secondary index is completed, notifying the multiple other nodes to update the metadata version from the first version to a second version, where the second version is used to indicate that the global secondary index is normally available; When the coordinating node satisfies the second preset condition, the metadata version is updated from the first version to the second version on the coordinating node, wherein the second preset condition includes receiving update feedback information returned by each of the multiple other nodes, and the update feedback information is used to indicate that the update of the second version has been completed.
8. The method according to claim 6 or 7, characterized in that: The step of waiting for all transactions of the data table on the coordinating node and the plurality of other nodes to be completed comprises: Notify the multiple other nodes to wait for all transactions on the data table to end; When the coordination node meets the specified condition, wait for all transactions of the data table on the coordination node to end, wherein the specified condition includes receiving waiting feedback information returned by each of the multiple other nodes, and the waiting feedback information is used to indicate that the waiting for the end of all transactions on the data table has been completed.
9. The method according to any one of claims 1 to 8, characterized in that: The notifying the multiple other nodes to configure the metadata of the global secondary index includes: Sending a structured query language SQL instruction to the multiple other nodes, where the SQL instruction is used to instruct the multiple other nodes to configure metadata of the global secondary index.
10. A distributed system, characterized in that: The distributed system comprises a coordinating node and a plurality of other nodes, wherein: The coordinating node is used to send instructions to the multiple other nodes during the online creation process of the global secondary index, wherein the instructions are used to instruct the multiple other nodes to configure metadata of the global secondary index, wherein the metadata includes a metadata version, and the configuration is used to update and / or generate the metadata; Each node among the multiple other nodes is used to receive the instruction, and in response to the instruction, configure metadata of the global secondary index on its own node; The coordination node is further used to configure metadata of the global secondary index on the coordination node when the coordination node meets a preset condition.
11. The system according to claim 10, characterized in that Each of the multiple other nodes is further configured to return completion feedback information to the coordination node when completing metadata configuration of the global secondary index on its own node; The coordination node is further configured to determine that the coordination node meets the preset condition when receiving the completion feedback information returned by each of the multiple other nodes.
12. The system according to claim 10 or 11, characterized in that The instructions include a first instruction, and the first instruction is used to instruct the multiple other nodes to generate metadata of the global secondary index; The distributed system also includes a client, wherein: The client is used to send an index creation request, where the index creation request is used to instruct online creation of a global secondary index; The coordinating node is configured to receive the index creation request, and send the first instruction to the plurality of other nodes in response to the index creation request; Each node among the multiple other nodes is used to receive the first instruction, and in response to the first instruction, create and initialize the metadata of the global secondary index on its own node, and set the metadata version in the metadata to the first version; The coordination node is further used to create and initialize the metadata of the global secondary index on the coordination node when the coordination node meets a preset condition, and set the metadata version in the metadata to the first version.
13. The system according to claim 10 or 11, characterized in that: The instruction includes a second instruction, and the second instruction is used to instruct the multiple other nodes to update metadata of the global secondary index, wherein: The coordinating node is configured to send the second instruction to the multiple other nodes when the coordinating node and the multiple other nodes have completed the first version setting of the metadata version in the metadata of the global secondary index; Each node among the plurality of other nodes is configured to receive the second instruction, and in response to the second instruction, update the metadata version from the first version to the second version on the node itself; The coordination node is further configured to update the metadata version from the first version to the second version on the coordination node when the coordination node meets a preset condition.
14. The system according to claim 10 or 11, characterized in that The global secondary index is associated with a field on a data table, and the instruction includes a second instruction, where the second instruction is used to instruct the multiple other nodes to update metadata of the global secondary index, wherein: The coordinating node is configured to fill the relevant data in the data table into the global secondary index when the coordinating node and the multiple other nodes complete the first version setting of the metadata version in the metadata of the global secondary index, and send the second instruction to the multiple other nodes when the data filling of the global secondary index is completed; Each node among the plurality of other nodes is configured to receive the second instruction, and in response to the second instruction, update the metadata version from the first version to the second version on the node itself; The coordination node is further configured to update the metadata version from the first version to the second version on the coordination node when the coordination node meets a preset condition.
15. The system according to claim 13 or 14, characterized in that The global secondary index is associated with a field on the data table, and the coordinating node is further used to wait for all transactions of the data table on the coordinating node and the multiple other nodes to end after the coordinating node and the multiple other nodes have completed the first version setting of the metadata version in the metadata of the global secondary index.
16. The system according to claim 10 or 11, characterized in that The preset condition includes a first preset condition and a second preset condition, the instruction includes a first instruction and a second instruction, the first instruction is used to instruct the multiple other nodes to generate metadata of the global secondary index, and the second instruction is used to instruct the multiple other nodes to update the metadata of the global secondary index; The distributed system also includes a client, wherein: The client is used to send an index creation request, where the index creation request is used to instruct online creation of a global secondary index associated with a field on a data table; The coordinating node is configured to receive the index creation request, and send the first instruction to the plurality of other nodes in response to the index creation request; Each of the multiple other nodes is used to receive the first instruction, and in response to the first instruction, create and initialize the metadata of the global secondary index on its own node, and set the metadata version in the metadata to the first version, where the first version is used to indicate that the global secondary index is writable but not readable; Each of the multiple other nodes is further configured to return setting feedback information to the coordination node when completing the creation and initialization of the metadata and completing the setting of the first version on its own node; The coordinating node is further configured to, upon receiving the setting feedback information returned by each of the multiple other nodes, determine that the coordinating node satisfies the first preset condition, and when the coordinating node satisfies the first preset condition, create and initialize metadata of the global secondary index on the coordinating node, and set the metadata version in the metadata to the first version; The coordinating node is further configured to fill the relevant data in the data table into the global secondary index after waiting for all transactions of the data table on the coordinating node and the multiple other nodes to be completed, and send the second instruction to the multiple other nodes when the data filling of the global secondary index is completed; Each of the multiple other nodes is further configured to receive the second instruction, and in response to the second instruction, update the metadata version from the first version to a second version on its own node, where the second version is used to indicate that the global secondary index is normally available; Each of the multiple other nodes is further configured to return update feedback information to the coordination node when completing the update of the second version on its own node; The coordination node is also used to determine whether the coordination node meets the second preset condition when receiving the update feedback information returned by each of the multiple other nodes, and to update the metadata version from the first version to the second version on the coordination node when the coordination node meets the second preset condition.
17. The system according to claim 15 or 16, characterized in that The instructions further include a third instruction, and the third instruction is used to instruct the multiple other nodes to wait for all transactions on the data table to be completed, wherein: The coordinating node is further configured to send the third instruction to the plurality of other nodes; Each of the multiple other nodes is further configured to receive the third instruction, respond to the third instruction, and wait for all transactions of the data table on the own node to be completed; Each of the multiple other nodes is further configured to return waiting feedback information to the coordination node when the waiting for all transactions on the data table to be completed is completed on the own node; The coordinating node is also used to determine whether the coordinating node meets specified conditions when receiving the waiting feedback information returned by each of the multiple other nodes, and wait for all transactions of the data table on the coordinating node to end when the coordinating node meets the specified conditions.
18. The system according to any one of claims 10 to 17, characterized in that: The instructions are structured query language SQL instructions.
19. An index creation device in a distributed system, characterized in that: The device is applied to a coordination node in the distributed system, wherein the distributed system further includes a plurality of other nodes, and comprises: A processing unit, configured to notify the plurality of other nodes to configure metadata of the global secondary index during online creation of the global secondary index, wherein the metadata includes a metadata version, and the configuration is used to update and / or generate the metadata; The processing unit is further configured to configure metadata of the global secondary index on the coordinating node when the coordinating node meets a preset condition.
20. A coordination node in a distributed system, characterized in that: The coordination node includes a memory and one or more processors; the memory and the processor are coupled; the memory is used to store computer program code, the computer program code includes computer instructions, and when the processor executes the computer instructions, the coordination node executes the method as described in any one of claims 1-9.
21. A chip system, characterized in that: The chip system includes one or more interface circuits and a processor; the interface circuit and the processor are interconnected via lines; the interface circuit is used to receive signals and send the signals to the processor, wherein the signals include instructions; when the processor executes the instructions, the chip system executes the method as described in any one of claims 1-9.
22. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 9.
Citation Information
Cited By
Index creation method and apparatus in distributed system
EP4726567A1
Index creation method and apparatus in distributed system
WO2025020531A1