Index creation method and apparatus in distributed system

Through the online creation process of governing the global second -level index in the distributed database, the problem of high performance and high availability in the creation process is solved, and efficient inquiries have been achieved.

WO2025020531A1PCT designated stage expired Publication Date: 2025-01-30HUAWEI TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/079444
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-07-24
Filing Date
2024-02-29
Publication Date
2025-01-30

AI Technical Summary

Technical Problem

In distributed databases, it is difficult to ensure high performance and high availability when creating global secondary indexes, especially in systems with large scale and many nodes, the query efficiency is not high.

Method used

By the online creation process of managing global second -level indexes on coordinating nodes, multiple other nodes are notified to configure metadata and synchronize metadata when meeting the preset conditions to achieve non -exotic update of metadata.

Benefits of technology

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 the query efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024079444_30012025_PF_FP_ABST
    Figure CN2024079444_30012025_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computers, and discloses an index creation method and apparatus in a distributed system. In the online creation process of a global secondary index, non-asynchronous updating of metadata can be realized when a third-party node / tool with a high concurrent access load is not introduced. In the solution, in the online creation process of a global secondary index, a coordinator node first notifies a plurality of other nodes to configure metadata of the global secondary index, wherein the metadata comprises a metadata version, and the configuration is used for updating and / or generating the metadata; and only when the coordinator node meets a preset condition, the metadata of the global secondary index is configured on the coordinator node.
Need to check novelty before this filing date? Find Prior Art

Description

Method and device for creating index in distributed system

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on July 24, 2023, with application number 202310916238.8 and application name “A method and device for creating an index in a distributed system”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] 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

[0003] A distributed system consists of a collection of stations, also known as nodes or agents, connected via a communication network. Each node is an independent database system, including its own database, central processing unit (CPU), terminal, and local database management system. It can be thought of as a collection of centralized database systems, logically part of the same system but physically distributed.

[0004] In a distributed database, data in each table is partitioned or sharded according to certain rules and then distributed across multiple nodes. This data can be multiple records in a table, and the database instance running on each node manages the records assigned to that node. For example, a column or columns in a table can be used as the table's distribution key, and the data in the table can be partitioned or sharded based on the hash value of the distribution key column. The data in the partitioned or sharded table is then stored across multiple nodes based on the distribution key.

[0005] Currently, when querying data in a database, if the query is based on the distribution key of a data table, the desired user data can be quickly found. However, if the query is based on any 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 large-scale distributed systems with many nodes, this results in low query efficiency due to the need to establish network communication with a large number of nodes. Therefore, it is necessary to introduce global secondary indexes (GSIs) to support queries based on other columns of the data table, thereby enabling distributed databases to support flexible query capabilities in more dimensions. A global secondary index is a global index that applies to all data nodes in a distributed database and can be created based on specific user needs. However, to avoid blocking data manipulation language (DML) transactions that affect user services, global secondary index (GSI) creation is currently typically performed online, but high performance or high availability (HA) during the creation process is difficult to guarantee.

[0006] Summary of the Invention

[0007] The present application provides an index creation method and device 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.

[0008] To achieve the above objectives, this application adopts the following technical solutions:

[0009] 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: during the online creation process of a global secondary index, notifying the 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.

[0010] The online creation of a global secondary index can be understood as the simultaneous and parallel processing of user business DML transactions during the creation of the global secondary index without blocking each other.

[0011] The coordinating node can be any coordinating node in the distributed system that receives an online creation request for a global secondary index. When another coordinating node in the distributed system receives an online creation request for a new global secondary index, the other coordinating node can also execute the index creation method in the distributed system provided by this solution.

[0012] Optionally, the multiple other nodes notified by the above-mentioned coordinating node may include data nodes, and may also include other coordinating nodes.

[0013] 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. As an example, from the start of creation to the completion of creation of a 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 a global secondary index, the version states of metadata transition can only include absent, write only (data reorganization), and public.

[0014] Optionally, the preset condition satisfied by the coordinating node may be a condition that confirms that each of the multiple other nodes has completed metadata configuration for the global secondary index. In this way, the coordinating node can confirm whether each of the multiple other nodes has completed metadata configuration for the global secondary index by determining whether the preset condition is satisfied.

[0015] 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 synchronizes the configuration of 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 the extra burden on the node due to the fixed execution of 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 of the global secondary index, high concurrent performance under large-scale clusters can be effectively guaranteed.

[0016] In one 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 the 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.

[0017] In one 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 process of online creation of a global secondary index, when the coordination node notifies multiple other nodes to complete metadata configuration, it can, after waiting for a certain period of time, assume that multiple other nodes have completed the corresponding metadata configuration, thereby realizing automatic confirmation of the completion of metadata configuration of multiple other nodes. It is understandable that this is not limited to the metadata generation stage or the update stage, or the waiting stage for all DML transactions. After notification, the coordination node can automatically confirm that multiple other nodes have completed configuration after waiting for a certain period of time.

[0018] In one possible implementation, the distributed system also includes a client. When the above configuration is used to generate metadata, the above process of generating metadata for 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 for the global secondary index, and setting the metadata version of the global secondary index to the first version; when the coordination node meets preset conditions, creating and initializing metadata for the global secondary index on the coordination node, and setting the metadata version of the global secondary index to the first version.

[0019] Optionally, the preset condition satisfied by the coordinating node may be: receiving setup feedback information returned by each of the multiple other nodes. The setup feedback information returned by each node may be used to indicate that the creation and initialization of metadata for the global secondary index on its node, as well as the setup of the first version, have been completed.

[0020] Thus, during the online creation of a global secondary index, the coordinating node can, during the metadata generation phase (initialization phase) of the global secondary index, first notify and wait for multiple other nodes to complete metadata initialization and metadata versioning, and then synchronously complete metadata initialization and metadata versioning on its own node (i.e., the coordinating node executing this scheme's index creation method). This enables non-asynchronous metadata initialization during the online creation of a global secondary index using the coordinating node, ensuring not only global metadata consistency but also high concurrent performance in large-scale clusters.

[0021] Optionally, the first version may be the 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 also be other versions.

[0022] 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 coordination 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 coordination node meets the preset conditions, updating the metadata version from the first version to the second version on the coordination node.

[0023] Optionally, the preset condition satisfied by the coordinating 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 the node has been completed.

[0024] This solution allows the coordinating node to notify and wait for multiple other nodes to complete metadata and metadata version updates during the metadata update phase of a global secondary index during online creation. The coordinating node then synchronously completes the metadata and metadata version updates on its own node. This enables non-asynchronous metadata updates during online global secondary index creation, ensuring both global metadata consistency and high concurrency performance in large-scale clusters.

[0025] Optionally, the second version may be an intermediate compatible version set during the metadata update phase, which is not limited in this solution. For example, it may be a write-only version. The first version may be the previous version before the second version, which may be the starting version set during the metadata initialization phase or the previous intermediate compatible version. For example, if the second version to be updated is a write-only version, the previous version may be a delete-only version.

[0026] In one 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, the relevant data in the data table is filled into the global secondary index; when it is confirmed that the data filling of the global secondary index is completed, multiple other nodes are notified to update the metadata version from the first version to the second version; when the coordination node meets the preset conditions, the metadata version is updated from the first version to the second version on the coordination node.

[0027] Optionally, the preset condition satisfied by the coordinating 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.

[0028] Thus, during the online creation of a global secondary index, this solution allows the coordinating node to enter the final metadata update phase of the global secondary index after completing the data population of the global secondary index, indicating that the global secondary index has been successfully created and is available. Furthermore, during this final metadata update phase, the coordinating node first notifies and waits for multiple other nodes to complete the final metadata update and metadata version update before synchronously completing the final metadata update and metadata version update on its own node. This utilizes the coordinating node to implement a non-asynchronous final metadata update during the online creation of the global secondary index, ensuring not only global metadata consistency but also high concurrent performance in large-scale clusters.

[0029] Optionally, the second version may be the final version set during the metadata update phase, which is not limited in this solution. For example, it may be a publicly available version. This version status is used to indicate that the global secondary index has been 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 during the metadata initialization phase or the previous intermediate compatible version. For example, when the second version to be updated is a public version, the previous version may be a write-only version.

[0030] In a possible implementation, after the 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 further include: waiting for all transactions of the data table on the coordination node and multiple other nodes to be completed. Then the coordination node executes the subsequent process. In this way, in the process of online creation 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 enters the waiting phase for the completion of user DML transactions to wait for all currently active DML transactions to complete. Then it updates to the next version V n+1 In this way, during the online creation of global secondary indexes, the coordinating node can prioritize user DML transactions and complete asynchronous metadata updates. This not only ensures the consistency of base table and index data under the asynchronous metadata update mechanism, but also ensures high availability during the creation process without hindering the normal execution of user DML transactions.

[0031] Optionally, after all transactions on the data table between the coordinating node and multiple other nodes have concluded, the coordinating node may execute the aforementioned subsequent process. For example, after all transactions on the data table between the coordinating node and multiple other nodes have concluded, the coordinating node may notify the multiple other nodes to update the metadata of the global secondary index and update the metadata version of the global secondary index from the first version to the second version. Alternatively, after all transactions on the data table between the coordinating node and multiple other nodes have concluded, the coordinating node may populate the global secondary index with the relevant data from the data table.

[0032] 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 above-mentioned process of generating and updating metadata of the global secondary index during 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 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, 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 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 end, 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.

[0033] Optionally, the first preset condition satisfied by the coordinating node may be: receiving setup feedback information returned by each of the multiple other nodes. The setup feedback information returned by each node may be used to indicate that setup of the first version of the metadata version of the global secondary index on its node has been completed.

[0034] Optionally, the second preset condition satisfied by the coordinating node may be: receiving update feedback information returned by each of the multiple other nodes. 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.

[0035] In this way, during the online creation of the global secondary index, the coordinating node can complete the initialization and metadata version setting of the metadata of multiple other nodes and its own node using the aforementioned non-asynchronous mechanism, then wait for all transactions on the data tables on the coordinating node and multiple other nodes to end, and directly enter the data filling phase to generate the global secondary index. After the data filling is completed, the final update of the metadata and metadata versions of multiple other nodes and its own node is directly completed using the aforementioned non-asynchronous mechanism. The entire creation process only requires the state transition of two metadata versions. Therefore, this solution uses the coordinating node to not only realize the non-asynchronous update of metadata 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, and also ensuring high performance and high availability during the creation process.

[0036] 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.

[0037] Optionally, the specified condition satisfied by the coordinating 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 transactions on the data table have been completed on its node.

[0038] In this way, during the online creation of a global secondary index, the coordinating node can wait for all currently active DML transactions to complete, also using a non-asynchronous approach. This means that it first notifies and waits for multiple other nodes to complete all DML transactions, and then synchronously completes all DML transactions on its own node.

[0039] In one possible implementation, notifying multiple other nodes to configure metadata for the global secondary index includes sending SQL instructions to the multiple other nodes, where the SQL instructions are used to instruct the multiple other nodes to configure metadata for the global secondary index. In this way, during the online creation of the global secondary index, the coordinating node can directly instruct the multiple other nodes to complete the global secondary index metadata configuration using SQL instructions.

[0040] In a second aspect, a distributed system is provided, comprising a coordination node and multiple other nodes, wherein:

[0041] A coordinating node is configured to send instructions to multiple other nodes during the online creation process of a global secondary index, wherein 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;

[0042] Each of the multiple other nodes is configured to receive instructions, respond to the instructions, and configure metadata of the global secondary index on its own node;

[0043] The coordinating node is also used to configure metadata of the global secondary index on the coordinating node when the coordinating node meets preset conditions.

[0044] The coordinating node may be any coordinating node in the distributed system that receives an online creation request for a global secondary index. Optionally, the multiple other nodes notified by the coordinating node may include data nodes or other coordinating nodes.

[0045] Optionally, the preset condition satisfied by the coordinating node may be a condition that confirms that each of the multiple other nodes has completed metadata configuration for the global secondary index. In this way, the coordinating node can confirm whether each of the multiple other nodes has completed metadata configuration for the global secondary index by determining whether the preset condition is satisfied.

[0046] The solution provided in the second aspect above, for a distributed system comprising a coordinating node and multiple other nodes, enables any coordinating node to be directly responsible for the entire online creation process of a global secondary index. Furthermore, during the online creation of a global secondary index, the coordinating node instructs multiple other nodes in the distributed system to perform metadata configuration operations for the global secondary index by sending instructions to the other nodes. Thus, the multiple other nodes can receive instructions from the coordinating node and, in response to the instructions, perform the corresponding metadata configuration operations for the global secondary index. After confirming that the multiple other nodes have completed the metadata configuration for the global secondary index, the coordinating node then synchronously configures the metadata for the global secondary index on its own node. In this way, this solution can implement online creation of a global secondary index in a distributed system based on synchronous metadata updates (non-asynchronous updates) while ensuring global metadata consistency. Furthermore, since the node that performs online creation of a global secondary index in this solution is not a specific node, but can be executed by any coordinating node in the distributed system, this eliminates the need to frequently impose additional burdens on a specific node by assigning it to perform online creation of the global secondary index, and eliminates the need to introduce third-party nodes / tools with high concurrent access loads to coordinate metadata updates. In this way, the distributed system can effectively guarantee concurrent high performance in large-scale clusters during the online creation of global secondary indexes.

[0047] In a possible implementation, each of the multiple other nodes is further configured to return completion feedback information to the coordinating node when completing metadata configuration of the global secondary index on its own node;

[0048] The coordinating node is further configured to receive completion feedback information and, upon receiving completion feedback information returned by each of the multiple other nodes, determine that the coordinating node meets a preset condition. Thus, in a distributed system comprising the coordinating node and the multiple other nodes, upon receiving an instruction from the coordinating node and completing the configuration operation of metadata for the corresponding global secondary index in response to the instruction, the multiple other nodes in the distributed system can return an indication to the coordinating node, allowing the coordinating node to promptly confirm that the metadata configuration has been completed by the multiple other nodes.

[0049] In one possible implementation, the coordinating node is further configured to determine whether the coordinating node meets a preset condition after waiting for a preset processing time. Thus, during the online creation of a global secondary index, when the coordinating node notifies multiple other nodes that metadata configuration has been completed, the coordinating node can automatically assume that all other nodes have completed the corresponding metadata configuration after waiting for a certain period of time.

[0050] In one 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:

[0051] The client is used to send an index creation request, which is used to instruct the online creation of a global secondary index associated with a field on a data table;

[0052] a coordinating node, configured to receive an index creation request and, in response to the index creation request, send a first instruction to a plurality of other nodes;

[0053] Each of the multiple other nodes is configured to receive the first instruction, and in response to the first instruction, create and initialize metadata of the global secondary index on the node itself, and set the metadata version of the global secondary index to the first version;

[0054] 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 the preset conditions, and set the metadata version of the global secondary index to the first version.

[0055] 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 start 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 then 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 the metadata, but also ensures high concurrency performance under large-scale clusters.

[0056] Optionally, each of the multiple other nodes is further configured to return setting feedback information to the coordinating node when completing the creation and initialization of the metadata of the global secondary index and the setting of the first version of the metadata version on its own node;

[0057] 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.

[0058] In one possible implementation, when the above configuration is used to update metadata, the instructions 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 the multiple other nodes to update the metadata of the global secondary index.

[0059] The coordinating node is configured to send a second instruction to the plurality of other nodes when the coordinating 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;

[0060] Each of 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 from the first version to the second version;

[0061] 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.

[0062] Thus, in a distributed system comprising a coordinating node and multiple other nodes, the coordinating node can, during the metadata update phase of a global secondary index, instruct the other nodes to update the global secondary index by sending a second instruction to them. Upon confirming that the other nodes have completed the metadata update for the global secondary index, the coordinating node will then synchronously complete the metadata update for the global secondary index on its own node. This allows the coordinating node, which receives the global secondary index creation request, to implement a non-asynchronous metadata update mechanism during the online creation of the global secondary index, ensuring not only global metadata consistency but also high concurrent performance in large-scale clusters.

[0063] Optionally, each of the multiple other nodes is further configured to return update feedback information to the coordinating node when completing the second version update of the metadata version of the global secondary index on its own node;

[0064] The coordinating 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 coordinating node meets a preset condition.

[0065] In one 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), where the second instruction is used to instruct the multiple other nodes to update the metadata of the global secondary index, wherein:

[0066] 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 plurality of other nodes complete setting of the first version 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;

[0067] Each of 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 from the first version to the second version;

[0068] 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.

[0069] Optionally, each of the multiple other nodes is further configured to return update feedback information to the coordinating node when completing the second version update of the metadata version of the global secondary index on its own node;

[0070] The coordination node is also used to receive update feedback information, and when receiving the 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, 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 after completing the data filling of the global secondary index and entering the final metadata update stage 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 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 realize 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.

[0071] In one possible implementation, the coordinating node is further configured to wait for all transactions on the data tables on the coordinating node and multiple other nodes to complete after the coordinating node and multiple other nodes have completed setting the first version of the metadata in the metadata of the global secondary index. The coordinating node then executes the aforementioned subsequent process. In this way, in a distributed system including the coordinating node and multiple other nodes, the coordinating node can follow the principle of user DML transaction priority and complete asynchronous metadata updates. 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.

[0072] In one possible implementation, the preset conditions include a first preset condition and a second preset condition. When the configuration is used to generate and update metadata, the instructions sent by the coordinating node to multiple other nodes in the distributed system may include a first instruction and a second instruction, wherein 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:

[0073] The client is used to send an index creation request, which is used to instruct the online creation of a global secondary index associated with a field on a data table;

[0074] a coordinating node, configured to receive an index creation request and, in response to the index creation request, send a first instruction to a plurality of other nodes;

[0075] Each of the multiple other nodes is configured 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 a first version, where the first version is used to indicate that the global secondary index is writable but not readable;

[0076] The coordinating node is further configured to create and initialize 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;

[0077] The coordinating node is further configured to wait for all transactions in the data tables on the coordinating node and multiple other nodes to be completed, fill the relevant data in the data tables into the global secondary index, and send a second instruction to the multiple other nodes when the data filling in the global secondary index is completed;

[0078] 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 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;

[0079] The coordination node is further configured to update the metadata version from the first version to the second version on its own node when the coordination node meets a second preset condition.

[0080] In this way, in a distributed system consisting of a coordinating node and multiple other nodes, the coordinating node can not only utilize the aforementioned non-asynchronous mechanism to complete the metadata configuration during the online creation of global secondary indexes, 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 global secondary indexes, but also simplifies the metadata version transition process while still ensuring the global consistency of metadata. It also follows the principle of user DML transaction priority and does not fix a specific node to execute the online creation of global secondary indexes, ensuring high performance and high availability during the creation process.

[0081] Optionally, each of the multiple other nodes is further configured to return setting feedback information to the coordinating node when completing the first version setting of the metadata version of the global secondary index on its own node;

[0082] 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.

[0083] Optionally, each of the multiple other nodes is further configured to return update feedback information to the coordinating node when completing the second version update of the metadata version of the global secondary index on its own node;

[0084] The coordinating 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 coordinating node meets the second preset condition.

[0085] In one possible implementation, the instruction sent by the 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 the multiple other nodes to wait for all transactions on the data table to end, where:

[0086] The coordinating node is further configured to send a third instruction to a plurality of other nodes;

[0087] 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;

[0088] 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.

[0089] In this way, in a distributed system consisting of a coordinating node and multiple other nodes, the coordinating node can also utilize the aforementioned non-asynchronous mechanism to complete the wait for all DML transactions during the online creation of a global secondary index. Specifically, the coordinating node sends a third instruction to multiple other nodes in the distributed system, instructing them to wait for all DML transactions. Once the coordinating node determines that all DML transactions have completed, it then synchronously completes the wait for all DML transactions on its own node.

[0090] Optionally, each of the multiple other nodes is further configured to return waiting feedback information to the coordinating node when all unfinished transactions on the data table are completed on its own node;

[0091] The coordinating 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 coordinating node meets a specified condition.

[0092] In one possible implementation, the instructions are SQL instructions. Thus, in a distributed system comprising a coordinating node and multiple other nodes, the coordinating node instructs the multiple other nodes to perform global secondary index metadata configuration operations by sending SQL instructions to the multiple other nodes in the distributed system.

[0093] In a third aspect, an index creation apparatus in a distributed system is provided, which is applied to a coordinating node in the distributed system, the distributed system also including multiple other nodes. The apparatus includes: a processing unit, configured to notify the multiple 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 configured to update and / or generate the metadata;

[0094] The processing unit is further configured to configure metadata of the global secondary index on the coordinating node when the coordinating node meets preset conditions.

[0095] 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 coordinating node meets a preset condition.

[0096] In a possible implementation, the processing unit is further configured to: after waiting for a preset processing time, determine whether the coordination node meets a preset condition.

[0097] In one possible implementation, the distributed system further includes a client. When the above configuration is used to generate metadata, the index creation device in the above distributed system may further include: a receiving unit, configured to receive an index creation request from the client, the index creation request being used to instruct online creation of a global secondary index associated with a field on a data table. The above processing unit is configured to: in response to the index creation request, notify multiple other nodes to create and initialize metadata for the global secondary index, and set the metadata version of the global secondary index to the first version. The above processing unit is further configured to: when the coordination node meets a preset condition, create and initialize metadata for the global secondary index on the coordination node, and set the metadata version of the global secondary index to the first version.

[0098] In one possible implementation, the receiving unit is further configured to receive configuration feedback information. The processing unit is further configured to, upon receiving configuration feedback information returned by each of the multiple other nodes, determine that the coordinating node meets a preset condition. The configuration feedback information returned by each node may be used to indicate that creation and initialization of metadata for the global secondary index on that node, as well as configuration of the first version, have been completed.

[0099] In one possible implementation, when the above configuration is used to update metadata, the processing unit is configured to: when the coordinating node and multiple other nodes have completed setting the first version of the metadata version in the metadata of the global secondary index, notify the multiple other nodes to update the metadata version from the first version to the second version. The processing unit is further configured to: when the coordinating node meets a preset condition, update the metadata version from the first version to the second version on the coordinating node.

[0100] In one possible implementation, the receiving unit is further configured to receive update feedback information. The processing unit is further configured to, upon receiving update feedback information returned by each of the multiple other nodes, determine that the coordinating node meets a preset condition. 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 that node has been completed.

[0101] In one possible implementation, when the above configuration is used to update metadata, the processing unit is configured to: when the coordinating node and multiple other nodes have completed setting the first version of the metadata version in the metadata of the global secondary index, populate the relevant data from the data table into the global secondary index; and when the data population of the global secondary index is complete, notify the multiple other nodes to update the metadata version from the first version to the second version. The processing unit is further configured to: when the coordinating node meets preset conditions, update the metadata version from the first version to the second version on the coordinating node.

[0102] In a possible implementation, the processing unit is further configured to wait for completion of all transactions on the data tables on the coordinating node and the plurality of other nodes.

[0103] 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 further include: a receiving unit for receiving an index creation request from the client, the index creation request being 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, the first version being 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.

[0104] In one possible implementation, the receiving unit is further configured to receive configuration feedback information. The processing unit is further configured to, upon receiving configuration feedback information returned by each of the multiple other nodes, determine that the coordinating node satisfies the first preset condition. The configuration feedback information returned by each node may be used to indicate that creation and initialization of metadata for the global secondary index on that node, as well as configuration of the first version, have been completed.

[0105] In one possible implementation, the receiving unit is further configured to receive update feedback information. The processing unit is further configured to, upon receiving update feedback information returned by each of the multiple other nodes, determine that the coordinating node satisfies the second preset condition. 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 that node has been completed.

[0106] In a possible implementation, the processing unit is further configured to: notify multiple other nodes to wait for completion of all transactions on the data table; and wait for completion of all transactions on the data table on the coordinating node when the coordinating node meets specified conditions.

[0107] In one 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 coordinating node meets a specified condition. The waiting feedback information returned by each node may indicate that all pending transactions on the data table have been completed on that node.

[0108] In a possible implementation, the processing unit is configured 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 a global secondary index.

[0109] In a fourth aspect, a coordination node in a distributed system is provided, which coordination node includes one or more processors and one or more memories, and at least one computer program is stored in the one or more memories. The at least one computer program is loaded and executed by the one or more processors to execute the index creation method in a distributed system in the above-mentioned first aspect and any possible design method thereof.

[0110] In the 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.

[0111] 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.

[0112] It can be understood that the beneficial effects that can be achieved by the third aspect device, the fourth aspect coordination node, the fifth aspect chip system, and the sixth aspect computer storage medium provided above can refer to the beneficial effects in the first aspect and any possible implementation thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0113] FIG1 is a system diagram 1 of an index creation method provided by the related art;

[0114] FIG2 is a second system diagram of an index creation method provided by the related art;

[0115] FIG3 is a system diagram 3 of an index creation method provided by the related art;

[0116] FIG4 is a fourth system diagram of an index creation method provided by the related art;

[0117] FIG5 is a schematic diagram of the system architecture of a method for creating an index in a distributed system provided by an embodiment of the present application;

[0118] FIG6 is a schematic diagram of a software architecture flow of an index creation method in a distributed system provided in an embodiment of the present application;

[0119] FIG7 is a flow chart of a method for creating an index in a distributed system according to an embodiment of the present application;

[0120] FIG8 is a timing diagram of a method for creating an index in a distributed system provided by an embodiment of the present application;

[0121] FIG9 is a schematic diagram of data distribution in a distributed system provided by an embodiment of the present application;

[0122] FIG10 is another data distribution diagram provided in an embodiment of the present application;

[0123] FIG11 is a flow chart of a method for synchronously deleting tuples in a distributed system provided by an embodiment of the present application;

[0124] FIG12 is a flow chart of a method for inserting tuples after synchronously deleting tuples in a distributed system according to an embodiment of the present application;

[0125] FIG13 is a schematic diagram of data partitioning in a distributed system provided by an embodiment of the present application;

[0126] FIG14 is a schematic diagram of data partitioning in another distributed system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0127] 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 the indicated technical features. 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 "more" refers to two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships can 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.

[0128] For the purpose of reference and clarity, the technical terms, abbreviations or acronyms used below are summarized and explained as follows:

[0129] Index: A data structure that sorts the values ​​of one or more columns in a table, allowing for quick querying and updating of data. An index is like a table of contents in a book, allowing users to quickly find the desired content by following the page numbers in the table of contents.

[0130] Data Manipulation Language DML: A language used to implement operations on data in the database (such as query, insert, update, delete, etc.).

[0131] Distribution key: In a distributed database, a column (or combination of columns) that determines the database partition where a specific row of data is stored.

[0132] Index Key: A column (or combination of columns) that identifies an index entry.

[0133] Base Table: also known as basic table, data table, metadata permanently stored in the database, distinguished from indexes, views, etc.

[0134] 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.

[0135] Metadata (Schema): describes some data about the database itself, including metadata version, database name, database character set, table name, table size, number of rows in the table, table character set, table fields, table indexes, table description, field type, field precision, field description, etc.

[0136] Memtable: A data structure in a log structured merge tree (LSM) storage structure that stores recently written data, typically stored in memory. When the accumulated written data reaches a certain threshold, a background merge process merges it into the sorted string table (SSTable).

[0137] Sorted String Table (SSTable): A data structure used to store historical data in the LSM storage structure, generally stored on disk.

[0138] 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 facilitates fast querying and updating of data in a base database table. A global secondary index is a global index that applies to all data nodes in a distributed database. The index key is a column (or combination of columns) that identifies an index entry in a global secondary index.

[0139] A coordinator node (CN) is a node that performs data scheduling. The coordinator node can manage the data nodes that establish communication connections with the coordinator node and perform data scheduling between the data nodes.

[0140] A data node (DN) is a node used to process and store data. It receives data scheduling information from a coordination node and sends and receives data, or processes and stores data based on the received scheduling information.

[0141] Currently, in distributed databases, creating a global secondary index (GSI) often takes hours or even days when processing large amounts of data. To avoid blocking DML transactions, GSI creation must be performed online. This allows concurrent DML transactions to run without blocking each other.

[0142] In order to achieve online creation of distributed global secondary indexes, a multi-version metadata asynchronous update algorithm is currently usually adopted. 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. A specific node performs index creation, and after the specific node updates its own metadata version, other nodes asynchronously update the metadata version accordingly. In this way, the online creation of distributed global secondary indexes can be achieved while ensuring data consistency. Among them, data consistency in this solution means that after the distributed database completes the creation of the index on the base table, the index remains 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.

[0143] To ensure that a node maintains at most two valid metadata versions, a solution is to implement asynchronous metadata updates through a lease mechanism. Specifically, after a specific node performing index creation updates its metadata version, it waits for other nodes to asynchronously update their metadata versions within a lease period. If a node fails to update, the process is considered to have exited abnormally.

[0144] Exemplarily, as shown in FIG1 , from the start 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 deletion operation is performed on a certain data in the base table, if this data exists in the index, it will be deleted in the index. The version write only means that when a deletion, insertion, or update operation is performed on a certain data in the base table, the corresponding operation is also performed on this data in the index. Data reorganization refers to the process of filling the index with base table data. The version public indicates that the creation is complete and the index can be used to accelerate queries.

[0145] As shown in FIG1 , FIG1 shows a solution for implementing asynchronous metadata update using a lease mechanism.

[0146] First, a GSI creation command is forwarded to a specific node to instruct the specific node to perform index creation.

[0147] Then, at time T0, the node responsible for index creation creates and initializes index-related metadata, sets the metadata version to absent, and begins waiting for a lease time. Other nodes pull the metadata version absent and update themselves within the lease time.

[0148] Then, at time T1, a lease expires and the specific node updates to the delete-only metadata version and begins waiting for another lease. Other nodes begin pulling the delete-only metadata version to update themselves.

[0149] Then, at time T2, a lease expires and the specific node updates to the write-only metadata version, waiting for another lease. Other nodes then start pulling the write-only metadata version and updating themselves.

[0150] 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.

[0151] Finally, at time T4, data filling in the 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.

[0152] It can be seen that during the entire index creation process, metadata is updated asynchronously, that is, the metadata version V is updated at 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 adheres to the principle of adjacent metadata version compatibility. This means that at the same point in time during the creation process, a node is allowed to have two, and at most two, adjacent valid metadata versions. This ensures that no active transactions holding non-adjacent metadata versions exist simultaneously in the distributed database, guaranteeing data consistency between the base table and the index after index creation is complete.

[0153] However, for the solution of using lease mechanism to realize asynchronous metadata update as shown in FIG1, the specific node used to execute index creation updates 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 achieve GSI online creation, the synchronous 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.

[0154] From this, it can be seen that if the above-mentioned lease mechanism is used to implement the asynchronous metadata update solution, the index creation will take at least three leases, even when the data volume is relatively small. Secondly, in order to ensure the compatibility principle 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 one 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 the solution shown in Figure 1 that uses a lease mechanism to implement asynchronous metadata updates can realize the online creation of GSI and also ensures data consistency, it also limits the minimum execution time of creation, limits the maximum execution time of DML transactions, and cannot guarantee high availability.

[0155] As another solution, asynchronous metadata updates can be implemented through third-party components or tools. Specifically, after the node responsible for index creation updates its metadata version, it uploads the latest metadata version to the third-party component or tool. The third-party component or tool is responsible for synchronizing the latest metadata version with other nodes and then feeding it back to the specific node.

[0156] As an example, Figure 2 illustrates a solution for asynchronous metadata updates using a placement driver (PD). From the start to the completion of index creation, metadata must adhere to the principle of compatibility between adjacent metadata versions and must transition through multiple version states: absent, delete-only, write-only, data reorganization, and public.

[0157] As shown in Figure 2, 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 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 (a 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 feedbacks to PD, and PD feedbacks to the specific node. The specific node updates the metadata version to delete only.

[0158] Repeat the above steps until the specific node enters the metadata version data reorganization. The specific node waits for the currently active old transaction to complete, then obtains the current snapshot and populates the index with the base table data under the snapshot.

[0159] After the data is populated into the index, the designated node uploads the metadata version "data reorganization" to the PD. The PD pushes this to other nodes, and each node waits for the currently active old transaction to complete and updates the metadata version "data reorganization" from the PD. After completion, each node provides feedback to the PD. After receiving feedback from the PD, the designated node updates the metadata version "public." Index creation is complete. The designated node uploads the metadata version "public" to the PD, which then pushes this to other nodes.

[0160] It can be seen that for the solution of using the third-party tool PD to coordinate the asynchronous update of metadata as shown in Figure 2, the specific node used to perform index creation updates its own metadata version V n After that, you need to change your own metadata version V n Status is uploaded to PD. PD push version V n After the PD is sent to other nodes and the node is confirmed to be updated successfully, 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 solution follows the principle of user DML transaction priority, that is, specific nodes are updated to enter version Vn 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 .

[0161] However, for PD (one master and two backup nodes), as shown in Figure 2, 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 for distributed transactions; data distribution management, which issues data scheduling commands to specific nodes based on the real-time data distribution of each storage node, etc.

[0162] From this, it can be seen that if the above-mentioned third-party tool PD is used to coordinate asynchronous metadata updates, although online creation of GSI can be achieved 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 high concurrent performance in a large-scale cluster environment being affected, and the high concurrent performance during the creation process cannot be guaranteed.

[0163] As another example, Figure 3 illustrates a solution for asynchronous metadata updates using the global metadata management module (GMS). From the start to the completion of index creation, metadata must adhere to the principle of compatibility between adjacent metadata versions and must transition through multiple version states: absent, delete-only, write-only, data reorganization, and public.

[0164] As shown in Figure 3, first, the GSI creation command is forwarded to a specific node to instruct the specific node to execute index creation. The specific node used to execute index creation then creates and initializes index-related metadata, updates the metadata version to absent, 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 completes, it feedbacks to GMS, and GMS confirms that the updates of other nodes are complete and feedbacks to the specific node. The specific node updates to the metadata version delete only.

[0165] Repeat the above steps until the specific node is updated to the metadata version of data reorganization. The specific node obtains the current snapshot and populates the index with the base table data under the snapshot.

[0166] After the data index is populated, 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 from GMS, "data reorganization." After completion, each node reports back to GMS. After receiving feedback from GMS, the specific node updates the metadata version to public. Index creation is complete.

[0167] It can be seen that for the solution shown in Figure 3 using the third-party tool GMS to coordinate metadata asynchronous updates, the specific node used to execute index creation updates its own metadata version V n After that, you also need to change your own metadata version V n Status uploaded to GMS. GMS push version V n After the GMS feedback is sent to other nodes and 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, the 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 .

[0168] However, for GMS (which also has one master and two backup nodes), as shown in Figure 3, GMS itself is responsible for 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, which adds / deletes nodes, etc.

[0169] From this, we can see that if the above-mentioned third-party tool GMS is used to coordinate asynchronous metadata updates, although online creation of GSIs can be achieved 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 high concurrent performance in large-scale cluster environments being affected, and the high concurrent performance during the creation process cannot be guaranteed.

[0170] As another example, Figure 4 illustrates a solution for asynchronous metadata updates using a central root server. From the start to the completion of index creation, metadata must adhere to the principle of compatibility between adjacent metadata versions and must transition between multiple version states: absent, write-only (data reorganization), and public. It is understood that in this type of distributed database, a log-structured merge tree (LSM) data storage architecture can be used to simplify metadata version transitions while still ensuring data consistency.

[0171] As shown in Figure 4, first, the GSI creation command is forwarded to the central node Root Server (third-party node), which executes the index creation. The Root Server then initializes the index-related metadata and sets the metadata version to absent.

[0172] The root server then updates the metadata version to write-only, waits for the DML transaction holding the old version to complete, and asynchronously flushes it to other nodes.

[0173] Next, the Root Server waits until the process is complete, obtains the current snapshot, and populates the index with the base table data under the snapshot.

[0174] Finally, the population is complete, and if necessary, consistency checks are performed between the base table and index. After the population and verification are complete, the root server confirms that other nodes have updated the metadata version and has waited for the DML transactions holding the old version to complete. The root server updates the metadata version to public and asynchronously refreshes it to other nodes, completing index creation.

[0175] It can be seen that for the solution shown in Figure 4 that uses a third-party root server node to coordinate metadata asynchronous updates, the index creation command needs to be delivered to the root server node, and during the creation process, the root server node also 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 of 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 ends), and then the Root Server node can enter version Vn+1 .

[0176] However, the Root Server node (one master and multiple backup nodes) is itself the master control service node of the distributed system, and has already 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.

[0177] 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, 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.

[0178] In summary, if a lease mechanism is used to implement online creation of a global secondary index (GSI), a node that fails to successfully update metadata within the lease period will exit the node cluster, and any ongoing user DML transactions on that node will be forced to terminate and roll back, making high availability impossible to guarantee. If third-party components / tools are used to implement online creation of a global secondary index (GSI), the flexibility to connect all nodes in the cluster is required. Therefore, a global metadata management module or central node is typically used as this third-party component / tool. However, the global metadata management module or central node already carries many high-load, high-network communication tasks, such as data distribution management and distributed transaction management. Introducing the additional burden of online index creation will affect its high concurrent performance in large clusters. Therefore, current solutions for online creation of global secondary indexes (GSIs) struggle to guarantee high availability or high concurrent performance.

[0179] 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.

[0180] 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.

[0181] Please refer to Figure 5, which shows a distributed system architecture provided by an embodiment of the present application. The distributed system may include a user client, N coordinating nodes (CN or coordinator), and M data nodes (DN), where N and M are positive integers. The client and the coordinating node can communicate with each other, and the coordinating node can communicate with each data node.

[0182] The client can be used to receive instructions input by the user and send the instructions to the coordination node. For example, the instructions entered by the user on the client can include storage instructions, modification instructions, insert, update, delete (insert / update / delete, IUD) instructions, etc. In an embodiment of the present application, the distributed system can include at least one client, and the instructions entered by the user on the client can be instructions for creating a global secondary index (GSI). The client can receive the instructions for creating a GSI input by the user and send the instructions for creating a GSI to the coordination node.

[0183] In the embodiment of the present application, when a user sends a Create GSI instruction through a client, a coordinating node (e.g., Coordinating Node 1) in the distributed system can receive the Create GSI instruction. The coordinating node that receives the Create GSI instruction is responsible for the entire online GSI creation process and executes the index creation method provided in the embodiment of the present application.

[0184] In an embodiment of the present application, during the online creation process of the GSI by 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 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.

[0185] It can be understood that when a user sends an IUD operation instruction through a client, there will also be a coordination node (such as coordination node 2) in the distributed system 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 the 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.

[0186] As an example, when a user requests to store data, the coordination node can store the data on a data node based on the request. The data can include multiple sets of base table data, where a base table is a fundamental table (also called a data table) in a database. For any set of base table data, the base table data can include a distribution key. Based on the distribution key corresponding to the base table data, the coordination node can store the base table data on the data node corresponding to the distribution key.

[0187] Furthermore, a column in the base table data can be indexed, meaning 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. The coordinating node can store the index data on the data node corresponding to the distribution key based on the distribution key.

[0188] In the embodiments of the present application, an index distributed on a different data node than the base table can be referred to as a global secondary index (GSI). Accordingly, the aforementioned index data can also be referred to as global secondary index (GSI) data. For any set of GSI data, a corresponding distribution key for the GSI data can also be associated with the coordinating node. Based on the distribution key corresponding to the GSI data, the coordinating node can store the GSI data on the data node corresponding to the distribution key.

[0189] For example, a distributed system may include three data nodes: data node 1, data node 2, and data node 3, where 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.

[0190] Each set 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. This application does not limit the number of data nodes and the storage method of data in this application. In actual 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.

[0191] There are no specific requirements for the distribution of base table data and GSI data on data nodes. Possible distribution methods include hash distribution, range distribution, and list distribution. For example, for hash-distributed data, the corresponding data node can be determined by calculating the data's hash value. For range-distributed data, the corresponding data node can be determined directly based on the data's range. For list-distributed data, the corresponding data node can be determined directly based on the data's list mapping value.

[0192] Optionally, for any set of base table data, each base table data may correspond to a partition key. After the coordinating node determines the data node corresponding to the base table data, it may store the base table data in the storage unit corresponding to the partition key based on the partition key. Similarly, base table data may be partitioned in a variety of ways, such as hash, range, and list.

[0193] For example, for hash-partitioned data, the corresponding storage unit can be determined by calculating the data's hash value. For range-distributed base table data, the corresponding storage unit can be determined directly based on the data's range. For list-distributed base table data, the corresponding storage unit can be determined directly based on the data's list mapping value.

[0194] The coordination node may also send a mapping relationship of the base table data to each data node, where the mapping relationship is used to indicate the distribution logic between the base table data and the data nodes.

[0195] As an example, for hash-distributed base table data, the mapping relationship of the base table data may include a mapping relationship between each hash value and the data node corresponding to each hash value. For range-distributed base table data, the mapping relationship of the base table data may include a mapping relationship between each range and the data node corresponding to each range. For list-distributed base table data, the mapping relationship of the base table data may include a mapping relationship between each list mapping value and the data node corresponding to each list mapping value.

[0196] 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 following is a brief introduction to the base table data and GSI data in the embodiment of the present application.

[0197] 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 serve 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 can 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 can 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.

[0198] 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 located in the same column in the global secondary index belong to the same attribute, and data located in the same row belong to the same tuple. The same tuple can be stored in the same location.

[0199] In some embodiments, at least one column of data in a global secondary index (GSI) can serve as a distribution key for the global secondary index. The distribution key of the global secondary index (GSI) is used to determine the storage location of data in the global secondary index (GSI). The distribution key can be distributed using a hash distribution, a list distribution, a range distribution, or other methods.

[0200] 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 data of a set column, or can be data determined according to user instructions.

[0201] In this embodiment of the present application, coordinating nodes and data nodes can store metadata for base tables and global secondary indexes. Metadata displays the status of the base table or global secondary index on the current node. Optionally, metadata includes, but is not limited to, descriptive information about the database object, such as type, attributes, name, and metadata version.

[0202] In some embodiments, the instructions entered by the user on the client can also be query instructions. Upon receiving the query instruction, the client can send the query instruction to the coordination node. The coordination node can then send instruction information to the data node based on the query instruction. This instruction information may include query conditions and a query method. The data node can be used to store data, receive the instruction information from the coordination node, and perform corresponding operations based on the query conditions in the instruction information. The query method can be understood as whether to use the GSI to query data.

[0203] 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 base table other than the distribution key, 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 used in a controller.

[0204] Please refer to Figure 6, which shows an index creation method based on the above-mentioned distributed system provided by an embodiment of the present application. 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 creation command to other nodes.

[0205] In the above-mentioned distributed system, users can connect to the above-mentioned distributed system by logging into the client. As shown in Figure 6, after the user enters the online creation of the global secondary index GSI statement through the client, a coordination node 1 in the distributed system receives the online creation of the global secondary index GSI statement. At this time, the coordination node can serve as the node for executing the creation of the GSI index, responsible for the entire process of online creation of the GSI. After being processed by the parsing and optimization module, the online creation of the GSI statement enters the execution module, which can then issue a creation command to other nodes to instruct them to create and initialize the GSI metadata, and wait for all nodes (including itself) to complete the creation and initialization of the GSI metadata.

[0206] Other nodes can be other coordinating nodes and data nodes. As shown in Figure 6, coordinating node 1 can send a create command to coordinating node 2, data node 1, and data node 2, and wait for coordinating node 2, data node 1, and data node 2 to complete the creation and initialization of GSI metadata.

[0207] After each node completes GSI metadata creation and initialization through its own parsing, optimization, and execution modules, it provides feedback to coordinating node 1. After receiving feedback from all other nodes, coordinating node 1 issues a command to wait for the current active transaction to complete and waits for all nodes (including itself) to complete the wait for the current active transaction. After each node completes the wait for the current active transaction through its own parsing, optimization, and execution modules, it provides feedback to coordinating node 1. After receiving feedback from all other nodes, coordinating node 1 begins organizing base table data and populating it into the global secondary index GSI.

[0208] 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 realize 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.

[0209] For example, the functions of the parsing module can be implemented by a parser deployed in the coordination node, the functions of the optimization module can be implemented by an optimizer deployed in the coordination node, and the functions of the execution module can be implemented by an executor deployed in the data node. Of course, the functions of each of the above modules can also be implemented by other hardware devices, and this is not specifically limited in the embodiments of the present application.

[0210] Please refer to Figure 7, which is a flow chart of a method for creating an index in a distributed system provided by an embodiment of the present application. The method can be implemented by a coordination node in the distributed system, for example, by a processor in the coordination node, or by a logical function module in the coordination node. The method includes:

[0211] S701: The coordinating node receives a request to create a global secondary index (GSI).

[0212] In this embodiment of the present application, a user can log in to a client, connect to a distributed system, and enter a statement to create a GSI. The distributed system includes multiple nodes forming a node cluster, which can include at least one coordination node and at least one data node. The coordination node is primarily responsible for guiding related nodes to perform data processing and calculations. The data node is primarily responsible for storing data and performing calculations.

[0213] When a user enters a statement to create a GSI, a coordinating node in the distributed system receives the statement. The coordinating node responsible for the entire GSI creation process is responsible for managing the GSI creation process. It is understood that when the coordinating node receives the GSI creation statement, it determines that it has received the GSI creation request.

[0214] Optionally, the GSI creation statement entered by the user may indicate the target data table for the GSI. The target data table may be any base table in the distributed system, or multiple base tables. This allows the distributed system to determine the data table based on which the GSI should be created.

[0215] In an embodiment of the present application, the user may also input a delete, modify, update (IUD) statement, so that a coordination node in the distributed system may receive the IUD statement, and the coordination node that receives the IUD statement is responsible for performing the IUD operation on the data table.

[0216] For ease of distinction, the coordinating node that receives the user's input statement for creating a GSI can be defined as coordinating node 1, and the coordinating node that receives the user's input statement for creating an IUD can be defined as coordinating node 2. As shown in FIG8 , the user's input statement for creating a GSI is sent to coordinating node 1, so that coordinating node 1 can execute the index creation method in the distributed system provided by this application.

[0217] S702: The coordinating node responds to the GSI creation request and sends first instruction information to all other nodes. The first instruction information is used to instruct all other nodes to create and initialize metadata of the GSI.

[0218] In an embodiment of the present application, when a coordinating node is responsible for creating a GSI, the coordinating node may issue 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.

[0219] Optionally, the coordinating node can start transaction 1, which is committed after notifying and waiting for all nodes to complete the initialization and configuration of the 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 all nodes to complete the initialization of the GSI metadata.

[0220] As shown in Figure 8, after coordinating node 1 starts transaction 1, it sends create commands to coordinating node 2 and data node 1, respectively, instructing them to complete the creation and initialization of the GSI metadata. 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.

[0221] Optionally, upon receiving the first instruction information, each of all other nodes may create and initialize GSI-related metadata. After completing the GSI-related metadata creation and initialization, each node may set the GSI metadata version to be writable but not readable (write only).

[0222] As a method, after completing GSI metadata creation, initialization, and versioning, each of the other nodes can provide first feedback information to the coordinating node. The first feedback information indicates that GSI-related metadata creation and initialization have been completed. As shown in Figure 8 , after completing GSI-related metadata creation and initialization, coordinating node 2 and data node 1 each return a processing result indicating initialization completion to coordinating node 1.

[0223] Alternatively, a preset processing duration can be set for each of the other nodes, requiring each node to complete GSI metadata creation, initialization, and versioning within the preset processing duration. If a node fails to complete GSI metadata creation, initialization, and versioning within the preset processing duration, the current GSI online creation process is terminated, and the coordinating node restarts the GSI online creation process, re-responding to the GSI creation request and sending the first instruction message to all other nodes.

[0224] Optionally, if a node fails to complete creation, initialization, and versioning within a preset processing time, the node may provide feedback to the coordination node, indicating that the creation, initialization, and versioning of the GSI metadata for the node has failed. The coordination node may thereby terminate the current GSI online creation process and restart the GSI online creation process. It is understood that the embodiments of the present application do not limit the feedback method of each of the other nodes after executing GSI metadata creation, initialization, and versioning. The feedback method may also be other than the above-mentioned method, or no feedback operation may be performed.

[0225] S703: When the coordinating node determines that all other nodes have completed the creation and initialization of the metadata of the GSI, the coordinating node completes the creation and initialization of the metadata of the GSI on the coordinating node.

[0226] In the embodiment of the present application, the coordinating node only begins to create and initialize the metadata of its own GSI after confirming that all other nodes have completed the creation and initialization of the metadata for 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 during the online creation of the GSI.

[0227] Optionally, the coordinating node may confirm that all other nodes have completed the creation and initialization of the metadata of the GSI upon receiving the first feedback information sent by all other nodes.

[0228] Optionally, the coordinating node may automatically confirm that all other nodes have completed GSI metadata creation and initialization after waiting for the preset processing time. Optionally, if the coordinating node receives initialization failure indication information from a node during the waiting period, it may confirm that not all nodes have completed GSI metadata creation and initialization. In this case, the coordinating node may terminate the current GSI online creation process and restart the GSI online creation process, i.e., re-respond to the GSI creation request and send the first instruction information to all other nodes.

[0229] 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. It may also be other methods except the above confirmation method.

[0230] It can be understood that, unlike the asynchronous metadata update in related technologies, that is, a specific node first completes the metadata creation and initialization of the GSI, and then notifies other nodes through a third-party node / tool ​​to complete the metadata creation and initialization of the GSI, the coordination node in this solution first notifies and waits for all other nodes to complete the metadata creation and initialization of the GSI, and then synchronously completes the metadata creation and initialization of its own GSI, thereby realizing a non-asynchronous metadata update mechanism in the process of online GSI creation. And because the node that executes the online creation of the GSI 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 the node due to the fixed node executing the online creation of the GSI, 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.

[0231] It is 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 commit transaction 1 to end the transaction.

[0232] 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.

[0233] In this embodiment of the present application, after metadata initialization of the GSIs of all nodes is complete, the coordinating node can continue to issue a second instruction message to all other nodes. The second instruction message is used to instruct each of the other nodes to wait for all currently active DML transactions on the target data table to complete. In this solution, active transactions refer only to transactions that have not yet completed or been committed.

[0234] Optionally, the coordinator node can start transaction 2, notifying all nodes and waiting for them to complete all currently active transactions. As shown in Figure 8, after coordinator node 1 starts transaction 2, it sends a wait command to coordinator node 2 and data node 1, instructing them to wait for all currently active transactions to complete.

[0235] Optionally, upon receiving the second instruction, each of all other nodes can execute the command and wait for all currently active DML transactions on the target data table to complete. As a method, each of all other nodes can provide second feedback information to the coordinating node after completing the wait for all currently active transactions. The second feedback information indicates that all currently active DML transactions on the target data table have completed. As shown in Figure 8 , after waiting for all currently active DML transactions on the target data table to complete, coordinating node 2 and data node 1 each return a processing result indicating the completion of all currently active transactions to coordinating node 1.

[0236] Alternatively, a preset processing duration can be set for each of all other nodes, requiring each node to complete the waiting period for all currently active transactions within the preset processing duration. If a node fails to complete the waiting period for all currently active transactions within the preset processing duration, the current GSI online creation process is terminated, and the coordinating node restarts the GSI online creation process, i.e., responds to the GSI creation request again and sends the first instruction information to all other nodes. Optionally, the preset processing duration here can be the same as or different from the preset processing duration set during the aforementioned GSI metadata initialization phase.

[0237] Optionally, if a node fails to complete the waiting process for all currently active transactions within a preset processing time, it can provide a feedback indication to the coordinating node, indicating that the waiting process for all currently active transactions on that node has failed. The coordinating node can then terminate the current GSI online creation process and restart it.

[0238] It can be understood that the embodiment of the present application does not limit the feedback method of each node in all other nodes after executing the wait for all currently active transactions. It can also be other methods besides the above methods, or no feedback operation can be performed.

[0239] 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.

[0240] 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.

[0241] 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.

[0242] Optionally, the coordinating node may also automatically confirm that all other nodes have completed waiting for all currently active transactions after waiting for the preset processing duration. Optionally, if the coordinating node receives a waiting failure indication from a node during the preset processing duration, it may confirm that not all nodes have completed waiting for all currently active transactions. In this case, the coordinating node may terminate the current GSI online creation process and restart it, i.e., re-respond to the GSI creation request and send the first instruction information to all other nodes.

[0243] 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. It may also be other methods besides the above confirmation method.

[0244] S706: The coordinating node performs data filling of the GSI.

[0245] It can be understood that when all the currently active DML transactions of the coordinating node itself on the target data are completed, it can be considered that all the 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.

[0246] 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 destination data node, forming the GSI shard in data node 1 as shown in Figure 6.

[0247] For example, when the data in the target data table and GSI is distributed and stored across multiple nodes based on a hash distribution rule, the coordinating node calculates the inter-node address information of the data using a hash algorithm based on the distribution key value of the target data table. The coordinating node then inserts the acquired data and the calculated address information into the GSI of the data node, thereby populating the GSI with data.

[0248] Optionally, when the coordination node confirms that data filling of a related node (such as the destination data node corresponding to the above-mentioned GSI) is completed, it confirms that the data in the target data table under the snapshot has been scanned, and the data filling of the GSI is completed.

[0249] As a method, after the destination data node completes data filling, it can feedback a message indicating that data filling is complete to the coordination node, so that when the coordination condition receives the feedback information from the destination data node, it can confirm that the data filling of the destination data node is complete. Optionally, when the above-mentioned GSI corresponding to the destination data node includes coordination node 2 and data node 1, as shown in Figure 8, coordination node 1 can perform data filling on the GSIs on coordination node 2 and data node 1. After the coordination node 2 and data node 1 complete the data filling, they will each return a processing result indicating that the data filling has been completed to the coordination node 1.

[0250] 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.

[0251] 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 can also use other methods, such as waiting for a preset processing time to automatically confirm that the destination data node has completed data filling.

[0252] S707: The coordinating node sends a third instruction message to all other nodes. The third instruction message is used to instruct all other nodes to update metadata of the GSI.

[0253] 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.

[0254] As shown in Figure 8, 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.

[0255] Upon receiving the third instruction, each of the other nodes can set the GSI's metadata version to available (public). As a method, each of the other nodes can provide third feedback information to the coordinating node after completing the setting of the available (public) version. The third feedback information indicates that the GSI's metadata version update is complete. As shown in FIG8 , after completing the GSI's metadata version update, coordinating node 2 and data node 1 each return a processing result indicating the completion of the GSI's metadata version update to coordinating node 1.

[0256] Alternatively, a preset processing duration can be set for each of all other nodes, requiring each node to complete the setting of the available (public) version of the GSI metadata within the preset processing duration. If a node fails to complete the setting of the available (public) version of the GSI metadata within the preset processing duration, the current GSI online creation process is stopped, and the coordinating node restarts the GSI online creation process, i.e., responds to the GSI creation request again and sends the first instruction information to all other nodes. Optionally, the preset processing duration here can be the same as or different from the preset processing duration set above.

[0257] Optionally, if a node fails to complete the setup of the public version of the GSI metadata within a preset processing time, the node can provide an indication to the coordinating node indicating that the setup of the public version of the GSI metadata for the node has failed. The coordinating node can then terminate the current GSI online creation process and restart it.

[0258] It can be understood that the embodiment of the present application does not limit the feedback method of each node in all other nodes after executing the available (public) version setting of the GSI metadata. It can also be other methods besides the above methods, or it can be that no feedback operation is performed.

[0259] 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.

[0260] In this embodiment of the present application, after the coordinating node confirms that the metadata of the GSIs on all other nodes has been updated to the available (public) version, it begins to update the metadata version of the GSI on its own node. That is, the metadata version of the GSI on its own node is set to available (public). The metadata version of the GSI is now globally unified. This achieves data consistency under the asynchronous (synchronous) metadata update mechanism, ensuring high availability during the online GSI creation process.

[0261] Optionally, upon receiving the third feedback information sent by all other nodes, the coordinating node may confirm that all other nodes have completed the update of the available (public) version of the metadata of the GSI.

[0262] Optionally, the coordinating node may also automatically confirm that all other nodes have completed the GSI metadata available (public) version update after waiting for the above-mentioned preset processing time. Optionally, during the waiting period of the above-mentioned preset processing time, if the coordinating node receives a version update failure indication message from a node, it can be confirmed that not all nodes have completed the GSI metadata available (public) version update. At this time, the coordinating 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.

[0263] 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.

[0264] It is understood that once the coordinating node completes the metadata version update for its own GSI, the metadata version update for all nodes' GSIs can be considered complete. At this point, the coordinating node can commit transaction two to end the transaction, thereby completing the online creation of the GSI.

[0265] In the embodiment of the present application, after completing the online creation of the GSI, the coordination node can return the creation result to the client where the user is located, so that the user can quickly query other columns other than the distribution key based on the secondary index.

[0266] It is understandable 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.

[0267] In some embodiments, in order to reduce changes to related technologies, the original metadata version delete only can be retained, and the above-mentioned metadata version delete only update steps can be repeated. Exemplarily, the coordinating node can 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 the subsequent write-only version update, the current active transaction waiting, data filling and available (public) version update process.

[0268] As an example, when the coordinating node determines that the coordinating node and all other nodes have completed the delete-only version setting of the global secondary index, the coordinating node may send a 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 and the metadata write-only version update on its own node. After confirming that the write-only version update of the metadata of all nodes (including itself) is completed, the coordinating node sends the above-mentioned second instruction message to all other nodes. The second instruction message is used to instruct all other nodes to wait for the completion of the currently active transaction. When the coordinating node confirms that all other nodes have completed the waiting for all currently active transactions, it waits on its own node for the currently active transaction of the coordinating node to be completed. After confirming that the currently active transactions of all nodes (including itself) are completed, the coordinating node performs data filling of the GSI. After confirming that the data filling is completed, the coordinating node sends the above-mentioned third instruction message to all other nodes. The third 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 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.

[0269] Alternatively, this solution can prioritize user DML transactions. Specifically, the coordinating node first notifies and waits for other nodes to update to the delete-only version. After completing the delete-only version update on its own node, it acquires a metadata lock and waits for the transaction to complete (the transaction ends when the metadata version <= the delete-only version). Only then can the coordinating node initiate the write-only notification and wait for the next version, and then synchronize the write-only update on its own node. This ensures high availability during the online GSI creation process without hindering the normal execution of user DML transactions.

[0270] As an example, the coordinating node may send a sixth instruction message to all other nodes when it determines 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 completion of the currently active transaction. When the coordinating node confirms that all other nodes have completed the waiting for all currently active transactions, it waits for the completion of the currently active transaction of the coordinating node. After confirming that the currently 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 a 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 write-only version update of the metadata on its own node.

[0271] The following is a detailed introduction to the index creation method provided by this application using an example.

[0272] 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:

[0273] Table 1

[0274] Among them, studentid is a self-increasing 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 according to the studentid column. Exemplarily, the data distribution of data table A in the distributed system can be shown in Figure 9. Among them, data table A is fragmented into fragment 1 of table A (containing data of studentid[1, 2, ...]), fragment 2 of table A (containing data of studentid[3, 4, ...]), and fragment 3 of table A (containing data of studentid[5, 6, ...]). Among them, fragment 1 of table A is stored in data node 1, fragment 2 of table A is stored in data node 2, and fragment 3 of table A is stored in data node 3.

[0275] 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.

[0276] The following example describes a scenario where a user creates a global secondary index a on table A. The attributes of the global secondary index a are: classid (class ID) (index key and distribution key); name (student name) (additional key).

[0277] The statement to create a global secondary index a can be: "CREATE GLOBAL INDEX CONCURRENTLY a on A(classid)CONTAINING(name)DISTRIBUTE BY HASH(classid)", where CREATE GLOBAL INDEX creates a global secondary index, CONTAINING refers to an additional key, and DISTRIBUTE BY HASH indicates a hash distribution method. This statement means: On base table A, whose distribution key is class ID, a global secondary index a is created with class ID as the index key and distribution key, a hash distribution method, and the additional key being student name.

[0278] 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.

[0279] Then the coordination node 1 starts transaction one and notifies all waiting nodes to complete the initialization of the global secondary index a before committing 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 achieved by setting the status flag (indisvalid) corresponding to the global secondary index a in the system table to FALSE. 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 SHARE LOCK 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.

[0280] After coordinating node 1 confirms that all other nodes have completed the above operations, it creates and initializes the metadata for global secondary index a and sets the metadata version to write-only. During this process, a SHARE LOCK may be applied to table A. The coordinating node commits transaction 1, and the metadata version of global secondary index a is now globally unified.

[0281] 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 can be achieved by waiting for transactions that conflict with the SHARE LOCK lock on data table A to complete. The transactions that conflict with the SHARE LOCK lock here can be understood as other operations other than the query operations blocked above, such as IUD operations. After the wait is completed, a shared update exclusive (SHARE UPDATE EXCLUSIVE LOCK) lock is added to data table A, so that the read operation and DML operation on 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 receipt of feedback from all other nodes confirming the completion of the above operations, it waits for all currently active DML transactions on table A on its own node to complete and then applies a SHARE UPDATE EXCLUSIVE LOCK to table A. Alternatively, unlike the previous approach where each node waits for the completion of active transactions and locks before reporting back to coordinating node 1, coordinating node 1 can first wait for all active transactions to complete. Once it confirms receipt of feedback from all other nodes confirming the completion of the above operations, it then applies a SHARE UPDATE EXCLUSIVE LOCK to all nodes. In other words, waiting for active transactions to complete and applying locks can be performed separately.

[0282] Coordinating node 1 then organizes the data from table A to populate global secondary index a. In this step, coordinating node 1 first applies a row-exclusive lock to global secondary index a. This row-exclusive lock ensures that IUD operations on global secondary index a are not blocked, but blocks other operations, such as DDL operations. Coordinating node 1 then obtains the current snapshot and begins organizing the data required for global secondary index a (columns corresponding to the distribution key, index key, and additional key) from table A in the snapshot and populating it into global secondary index a.

[0283] The data can be filled using the SQL statement: "INSERT INTO a(classid, name, location information, version information) SELECT classid, name, location information, version information FROM A". This statement selects the class ID, student name, location information, and version information from data table A and inserts them into the global secondary index a. The location information indicates the location of the data in data table A and includes the node information (xc_node_hash) where the data is located and the storage location within the node (ctid). The data node where the data should be inserted is derived from the value of the distribution key classid of the global secondary index a using a hash algorithm.

[0284] 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.

[0285] In this application, during the data filling process of the data node of the global secondary index a, the data modifications caused by the IUD operation that occurs synchronously in the data table A need to be reflected in the global secondary index a accordingly to ensure the consistency of the data after the creation is completed.

[0286] For example, during the data filling process, when the same user or another user inputs an IUD operation request on 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 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 a.

[0287] 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 global secondary index a can obtain the data required by global secondary index a (columns corresponding to the partial key, index key, and additional key) and insert it into global secondary index a.

[0288] As an example, take inserting a row of data tuples (2, Xiao Wang, 12) into data table A as an example. 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.

[0289] Then, the tuple insertion operation for 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 insert operation of the data table A according to the distribution key class ID hash algorithm and then 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 the data information of the Xth column from all the columns returned by the aforementioned RETURNING. For example, $3 is used to indicate the extraction of the data information of the third column (i.e., classid) from the "studentid, name, classid, location information, version information" returned by the aforementioned RETURNING.

[0290] 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 global secondary index a can delete the corresponding data row in global secondary index a.

[0291] 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.

[0292] The data deletion operation on the global secondary index a can then be performed through the SQL statement: "DELETE FROM a WHERE classid=$3AND name=$2AND location information=$4AND 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 on 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. This SQL statement is calculated by the coordination node 2 or the data node that executes the deletion operation of the data table A according to the distribution key class ID hash algorithm and sent to the corresponding data node to execute the deletion operation.

[0293] It should be noted that when the data node of 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:

[0294] Case 1: The tuple (12, Xiao Wang, location information, version information) has been processed by the data filling process of the 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, as shown in Figure 11, the data node of 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 global secondary index a, and the data node of global secondary index a can delete the tuple to be deleted normally.

[0295] Case 2: The tuple (12, Xiao Wang, location information, version information) has not yet been processed by the online GSI creation data population process and has not yet been populated into global secondary index a. When the data node of global secondary index a deletes the data row, it cannot find this tuple.

[0296] At this time, the present application provides a data processing method, as shown in Figure 11, 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 wrong. 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-mentioned SQL statement "DELETE FROM a WHERE classid=$3AND name=$2AND location information=$4AND 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 in Figure 11, the pieced-to-be-deleted tuple 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.

[0297] Correspondingly, as shown in Figure 12, the data filling process for creating GSI online subsequently obtains the visible data in data table A based on the snapshot, and is able to scan the above-mentioned deleted tuple (2, Xiao Wang, 12). 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, it can quickly locate the storage location with the same index key in the global secondary index a based on its index key (class ID). After scanning and comparing, an insertion conflict is found. The global secondary index a already has a row (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), so 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.

[0298] After the global secondary index a is created, if a 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 corresponding data row, and the data will remain consistent.

[0299] 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.

[0300] As an example, take the case of updating the tuple (2, Xiao Wang, 12) to (2, Xiao Li, 12) in 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=12RETURNING 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.

[0301] Then, the data update operation on the global secondary index a can be performed through the SQL statement: "UPDATE a SET classid=$3AND name=$2AND location information=$4AND version information=$5WHERE classid=$8AND name=$7AND location information=$9AND 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 on 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 calculated by the coordination node 2 or the data node that executes the update operation of the data table A according to the distribution key class ID hash algorithm and sent to the corresponding data node to perform the update operation.

[0302] When a data node updates data in global secondary index a, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. First, the old tuple (12, Xiao Wang, location information, version information) is deleted, and then the new tuple (12, Xiao Li, location information_new, version information_new) is inserted. It should be noted that when deleting the old tuple, the second DELETE operation scenario described above may occur: the corresponding tuple cannot be found in global secondary index a. The corresponding handling method is the same as above and will not be repeated here.

[0303] In this way, after the global secondary index a is created, the data row in table A that is updated during the creation of the global secondary index a will also be updated accordingly, and the data will remain consistent.

[0304] In this way, during the data population process, if data modifications are caused by IUD operations occurring simultaneously in table A, corresponding data modifications can be made in global secondary index a using the aforementioned method, ensuring data consistency after global secondary index a is created. This ensures accurate data population during the online creation of global secondary index a without hindering the normal execution of user DML transactions. Finally, coordinating node 1 notifies and waits for all nodes to complete the metadata update for global secondary index a and then commits transaction two. In this step, coordinating node 1 generates a metadata version modification command and sends it to all other coordinating nodes and data nodes. This metadata version modification command can be the SQL statement ALTER INDEX{a}GSIVAILD. Each node executes the command, setting the metadata version to available (public), and then sends feedback to coordinating node 1 for completion. The available (public) version can be set by setting the status flag (indisvalid) corresponding to global secondary index a to TRUE in the system table. After confirming the feedback from all other nodes, coordinating node 1 sets its own metadata version to available (public). The coordinating node commits transaction two, and the metadata version of global secondary index a is now globally consistent.

[0305] The creation of global secondary index a is completed.

[0306] For example, after the online creation of global secondary index a on data table A is completed, the data distribution of global secondary index a in the distributed system can be as shown in Figure 10. Specifically, global secondary index a is sharded into shard 1 of global secondary index a (containing data of classid [13, 12, ...]), shard 2 of global secondary index a (containing data of classid [11, 9, ...]), and shard 3 of global secondary index a (containing data of classid [8, 7, ...]). Shard 1 of global secondary index a is stored on data node 1, shard 2 of global secondary index a is stored on data node 2, and shard 3 of global secondary index a is stored on data node 3.

[0307] As shown in Figure 10, the shards of global secondary index a are all sorted by the user-defined index key classid. This allows users to quickly find the desired data based on classid when searching based on global secondary index a.

[0308] As another example, the index creation method provided in this application can also be applied to a certain 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:

[0309] Table 2

[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 a 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 cash register system can receive the request and be responsible for creating the global secondary index of data table B.

[0312] The following example describes a scenario where a user creates a global secondary index b on table B. The attributes of global secondary index b are: cashierid (cashier ID) (index key, distribution key); counterid (checkout counter ID) (additional key); and fno (store floor 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 creates a global secondary index, CONTAINING refers to an additional key, and DISTRIBUTE BY RANGE refers to range distribution. This statement means: On base table B, whose distribution key is cashier ID, create a global secondary index b with the index key and distribution key being cashier ID, the distribution mode being range distribution, and the additional key being cashier ID and the 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 may 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 and then commits 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 commits 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 the waiting command ALTER TABLE{B}GSIWAITALL. Waiting for all DML transactions can be achieved by waiting for the completion of transactions that conflict with obtaining the SHARE LOCK lock on data table B. Then add a SHARE UPDATE EXCLUSIVE LOCK lock to data table B. Coordination node 1 sends a command 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 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 lock to each node.

[0317] Then, coordination node 1 organizes the data of data table B to be filled into 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 EXCLUSIVE LOCK 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 (the columns corresponding to the distribution key, index key, and additional key) from the data table B under the snapshot and fills 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) within 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 on 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 cash register 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, after 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. The data tuple insertion operation into 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". This statement means inserting the tuple (2, 1, STF231567) to be inserted, and at the same time returning 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. The 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 for 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 ID, mall floor number, location information and version information from the data content returned above, 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 then sent to the corresponding data node for execution. After the global secondary index b is created, the tuples added to 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 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 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=2RETURNING 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 floor number, cashier ID, location information and version information. Since the deletion condition for data table B is the mall floor number, it does not contain the distribution key (cashier ID), so 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 WHERE cashierid=$3AND counterid=$1AND fno=$2AND location information=$4AND 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 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] In case 1, the tuple (MNG695478, 3, 2, location information, version information) has been populated into global secondary index b by the online GSI creation process. When the data node of global secondary index b deletes a row, it finds this tuple in the data of global secondary index b and proceeds with the deletion normally.

[0327] In the second scenario, the tuple (MNG695478, 3, 2, location information, version information) has not yet been processed by the online GSI data population process and has not yet been populated 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, in this case, the present application provides a data processing method, as shown in Figure 11.

[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=$3AND counterid=$1AND fno=$2AND location information=$4AND 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 assembled tuple to be deleted 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, as shown in Figure 12, the data filling process for creating GSI online subsequently obtains the data visible in 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, the storage location with the same index key (cashier ID) can be quickly located in the global secondary index b according to its index key (cashier ID). After scanning and comparison, it is found that the global secondary index b already has a row (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 the query returns directly.

[0330] After the global secondary index b is created, if a 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 corresponding data row, 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=10WHERE fno=2RETURNING 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, mall floor number, cashier ID, location information and version information. The SQL statement can be broadcast by the coordinating node 2 to all data nodes to attempt deletion, because its deletion condition does not contain the distribution key.

[0332] Then, the data update operation of the global secondary index b can be performed through the SQL statement: "UPDATE b SET cashierid=$3,counterid=$1AND fno=$3 location information=$4AND version information=$5WHERE cashierid=$8AND counterid=$6AND fno3=7AND location information=$9AND 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-mentioned 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 according to the cashier ID range distribution algorithm and sent to the corresponding data node to perform the update operation.

[0333] When a data node updates data in global secondary index b, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. First, the old tuple (MNG695478, 3, 2, location information, version information) is deleted, and then the new tuple (MNG695478, 3, 10, location information, version information) is inserted. It should be noted that when deleting the old tuple, the second DELETE operation scenario described above may occur: the corresponding tuple cannot be found in global secondary index b. The corresponding handling method is the same as above and will not be repeated here.

[0334] After the global secondary index b is created, the data rows in table B that are updated during the creation of the global secondary index b will also be updated accordingly, and the data will remain 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 metadata version modification. 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 user-defined index key cashierid, when the user queries based on cashierid, the desired data can be quickly found 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, the product sales system has a data table. 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] City is the distribution key. Since products are sold only in a few fixed cities, table C uses list distribution. In particular, sales personnel are also within a fixed range.

[0340] When a user requests to create a global secondary index on table C, a coordinating node (a server or a virtual machine on the server) in the product sales system receives the request and is responsible for creating the global secondary index for table C. The following example describes a scenario where a user creates a global secondary index C on table C with the following attributes: saleman (salesperson) (index key, distribution key); saledate (sales time) (additional key); and sales_id (sales record ID) (additional key).

[0341] The statement to create a global secondary index c can be: "CREATE GLOBAL INDEX CONCURRENTLY c on C(saleman) CONTAINING (saledate, sales_id) DISTIBUTE BY LIST(saleman)", where CREATE GLOBAL INDEX creates a global secondary index, CONTAINING refers to an additional key, and DISTIBUTE BY LIST refers to distributing by list. This statement means: On data table C, with the distribution key being sales record ID, a global secondary index c is created with the salesperson as the index key and distribution key, a list distribution method, and the sales time and sales record ID as the additional keys.

[0342] 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.

[0343] 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. The 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 on 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.

[0344] 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 can be achieved by waiting for the completion of transactions that conflict with obtaining the SHARE LOCK lock on data table C. Then add a SHARE UPDATE EXCLUSIVE LOCK to data table C. Coordination node 1 sends a command 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.

[0345] 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 EXCLUSIVE LOCK 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 (the columns corresponding to the distribution key, index key, and additional key) from the data table C under the snapshot and fill it into the global secondary index b.

[0346] 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) within the node. The data node where the data should be inserted is obtained by the value of the global secondary index c distribution key saleman under the list distribution algorithm.

[0347] 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.

[0348] Similarly, during the filling process of the data nodes of the global secondary index c, the data modifications caused by the IUD operation on 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.

[0349] 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 as an example. The data tuple insertion operation into data table C can be performed through the SQL statement: "INSERT INTO C (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 inserts the tuple (2, Bob, 2023-06-02-11-23, Shenzhen) and returns the data for all columns in the tuple, including the salesperson, sales time, sales city, location information, and version information. Coordinating node 2 calculates the SQL statement based on the distribution key "sales city list" using the distribution algorithm and sends it to the corresponding data node for execution.

[0350] Then, the tuples of the global secondary index c can be inserted 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 data content returned above, 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 then sent to the corresponding data node for execution. After the global secondary index c is created, the tuples added to 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.

[0351] 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 deletion, because its deletion condition does not include the distribution key;

[0352] The data deletion operation on the global secondary index c can then be performed using the SQL statement: "DELETE FROM c WHERE saleman=$2AND saledate=$3AND saleid=$1AND location information=$5AND version information=$6". This statement extracts the required salesperson, sales date, sales record ID, location information, and version information from the returned data content as deletion conditions, and deletes the corresponding tuple (Bob, 2023-06-02-11-23, 2, location information, version information) from the global secondary index c. The SQL statement is calculated by the coordination node 2 or the data node that executes the delete operation on the data table C according to the distribution algorithm of the distribution key salesperson list and sent to the corresponding data node to execute the delete operation.

[0353] 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:

[0354] In case 1, the tuple (Bob, 2023-06-02-11-23, 2, location information, version information) has been populated into global secondary index c by the online GSI creation process. When the data node of global secondary index c deletes a row, it finds this tuple in the data of global secondary index c and deletes it normally.

[0355] Case 2: The tuple (Bob, 2023-06-02-11-23, 2, location information, version information) has not yet been processed by the data filling process for online GSI creation and has not yet been filled into the global secondary index c. This tuple cannot be found when the data node of the global secondary index c is deleted. Similarly, in this case, this application provides a data processing method, as shown in Figure 11.

[0356] 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=$2AND saledate=$3AND saleid=$1AND location information=$5AND 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 and piece together 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.

[0357] Correspondingly, as shown in Figure 12, the data filling process for creating GSI online subsequently obtains the visible data in the data table C based on the snapshot, and is able to scan the above-mentioned deleted tuple (2, Bob, 2023-06-02-11-23, Shenzhen). 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 a row (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.

[0358] After the global secondary index c is created, if a data row in table C is deleted during the creation of the global secondary index c, the global secondary index will also delete the corresponding data row, and the data will remain consistent.

[0359] 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 case of updating the tuple (3, Cathy, 2023-06-02-11-42, Shanghai) to (5, Cathy, 2023-06-02-11-42, Shanghai) with the condition of city=Shanghai in data table C. The tuple update of data table A can be performed 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, saleeman, saledata, city, location information, version information". This statement updates the tuple (3, Cathy, 2023-06-02-11-42, Shanghai) to (5, Cathy, 2023-06-02-11-42, Shanghai) based on the update condition and returns the data before and after the update for all columns, including salesperson, sales time, sales city, location information, and version information. The SQL statement is calculated by coordinating node 2 using the distribution algorithm for the sales city list distribution key and sent to the corresponding data node for execution.

[0360] The data update operation on the global secondary index c can then be performed through the SQL statement: "UPDATE c SET saleman=$2,saledate=$3,sale_id=$3,location information=$5,version information=$6WHERE saleman=$8AND saledate=$9AND sale_id=7AND location information=$11AND 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 the 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 according to the salesperson list distribution algorithm and sent to the corresponding data node to perform the update operation.

[0361] When a data node updates the corresponding data in the global secondary index c, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. First, the old tuple (Cathy, 2023-06-02-11-42, 3, location information, version information) is deleted, and then the new tuple (Cathy, 2023-06-02-11-42, 5, location information_new, version information_new) is inserted. It should be noted that when deleting the old tuple, the second DELETE operation described above 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 here.

[0362] After the global secondary index c is created, the data rows in table C that are updated during the creation of the global secondary index c will also be updated accordingly, and the data will remain consistent.

[0363] Finally, Coordinating Node 1 notifies and waits for all nodes to complete the metadata update for global secondary index c, then commits Transaction 2. This step follows the same execution logic as the aforementioned student registration system. Coordinating Node 1 generates the metadata version modification command ALTER INDEX{c}GSIVAILD and distributes it to all nodes. It then waits for each node to complete the metadata version modification. Coordinating Node 1 commits Transaction 2, and the metadata version of global secondary index c is now globally unified. The creation of global secondary index c is complete.

[0364] 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 found based on the global secondary index c.

[0365] As another example, the index creation method provided in this application can be applied to a student archive system based on a distributed system architecture. For example, the student archive 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:

[0366] Table 4

[0367] Because studentid is a self-increasing and unique attribute, data table D uses a hash distribution algorithm. Using the hash algorithm and based on the studentid column, data is distributed relatively evenly across the nodes of the distributed system. At the same time, on each node, data is partitioned and stored according to the value of the partition key, docid. That is, data table D is stored on the data node using the hash algorithm based on the studentid column. On the data node, data is further partitioned based on the partition key, docid. For example, data values ​​less than 300,000 are stored in one partition, while values ​​greater than or equal to 300,000 are stored in another partition. As shown in Figure 13, in data node 1 (containing data for studentid[1, 2, ...]), the tuple (1, 100, 101, Xiaoming, 11) is stored in partition 1, and the tuple (2, 500, 132, Xiaowang, 12) is stored in partition 2. In data node 2 (containing data of studentid[3, 4, ...]), the tuple (3, 200177, Xiao Zhang, 13) and the tuple (4, 200211, Xiao Li, 9) are stored in partition 1.

[0368] 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 may receive the request and be responsible for creating the global secondary index for data table D.

[0369] The following example describes a scenario where a user creates a global secondary index d on table D. The attributes of the global secondary index d are: classid (class ID) (index key and distribution key); docid (document ID) (additional key); and name (student name) (additional key).

[0370] The statement to create a global secondary index d can be: "CREATE GLOBAL INDEX CONCURRENTLY d on D(classid) CONTAINING (docid, name) DISTRIBUTE BY Hash(classid)", where CREATE GLOBAL INDEX creates a global secondary index, CONTAINING refers to an additional key, and DISTRIBUTE BY HASH refers to a hash distribution method. This statement means: on data table D, with the distribution key being class ID, a global secondary index d is created with the index and distribution keys being class ID, a hash distribution method, and additional keys being student name and profile ID.

[0371] First, a request for creating a global secondary index input by a user is sent to a coordination node in the archive system. This coordination node may be the coordination node 1 responsible for creating the global secondary index d.

[0372] Then the coordination node 1 starts transaction one and notifies all waiting nodes to complete the initialization of the global secondary index d before committing 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 on 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 SHARE LOCK 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.

[0373] After coordinating node 1 confirms that all other nodes have completed the above operations, it creates and initializes the metadata for global secondary index d and sets the metadata version to write-only. During this process, a SHARE LOCK may be applied to table D. Coordinating node 1 commits transaction 1, and the metadata version of global secondary index d is now globally unified.

[0374] 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 operations blocked above, such as IUD operations. After the wait is completed, a shared update exclusive (SHARE UPDATE EXCLUSIVE LOCK) lock is added to data table D, so that the read operation and DML operation on data table D will not be blocked. Then feedback is given to coordination node 1 to complete the above operations. After coordinating node 1 confirms that all other nodes have completed the above operations, it waits for all currently active DML transactions on table D on its own node to complete and then applies a SHARE UPDATE EXCLUSIVE LOCK to table D. Alternatively, coordinating node 1 waits for all active transactions on all nodes to complete before applying a lock on each node.

[0375] 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 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 indicates the data's location within the data table, including the node information (xc_node_hash) and the storage location within the node (ctid). The partition information indicates the partition location of the data within the data table, including the partition information within the node (tableoid). The data node to which the data should be inserted is derived using a hash algorithm using the value of the global secondary index d distribution key classid.

[0376] When the coordination 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.

[0377] Similarly, during the filling process of the data nodes of the global secondary index d, the data modifications caused by the IUD operation on 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 file 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.

[0378] In one scenario, after data table D processes the 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". This statement means to insert the tuple (2, 500132, 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, 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;

[0379] Then, the tuples of the global secondary index d can be inserted 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 data content returned above, 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 insert operation of the data table D according to the distribution key class ID hash algorithm and then sent to the corresponding data node for execution. After the global secondary index d is created, the tuples added to the data table D during the creation of the global secondary index d also have corresponding tuples in the global secondary index d, and the data remains consistent.

[0380] 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 case of deleting the tuple (2, 500132, Xiao Wang, 12) from data table D 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=2RETURNING 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;

[0381] Then, the data deletion operation on the global secondary index d can be performed through the SQL statement: "DELETE FROM d WHERE classid=$4AND docid=$2AND name=$3AND location information=$5AND version information=$6AND 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 calculated 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 and sent to the corresponding data node to execute the deletion operation.

[0382] 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:

[0383] In case 1, the tuple (12, 500132, Xiao Wang, location information, version information, partition information) has been populated into global secondary index d by the online GSI creation process. When the data node of global secondary index d deletes a row, it finds this tuple in the data of global secondary index d and proceeds with the deletion normally.

[0384] Case 2: The tuple (12, 500132, Xiao Wang, location information, version information, partition information) has not yet been processed by the online GSI data population process and has not yet been populated into global secondary index d. When the data node of global secondary index d deletes the data row, it cannot find this tuple. Similarly, this embodiment of the application provides a data processing method.

[0385] 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=$2AND name=$3AND location information=$5AND version information=$6AND 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.

[0386] 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 the tuple (2, 500132, Xiao Wang, 12) can be scanned. 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, the storage location with the same index key (class ID) can be quickly located in the global secondary index d according to its index key (class ID). After scanning and comparison, it is found that the global secondary index d already has a row (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.

[0387] After the global secondary index d is created, if a 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 corresponding data row, and the data will remain consistent.

[0388] 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=12 RETURNING 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". This statement updates the tuple (2, 500132, Xiao Wang, 12) to (2, 500132, Xiao Li, 12) based on the update condition and returns the data 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 coordinating node 2 using the distribution key student ID hash algorithm and sent to the corresponding data node for execution.

[0389] Then, the data update operation on the global secondary index d can be performed through the SQL statement: "UPDATE d SET classid=$4AND docid=$2AND name=$3AND location information=$5AND version information=$6AND partition information=$7WHERE classid=$11AND docid=$9AND name=$10AND location information=$12AND version information=$13AND 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-mentioned 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). The SQL statement is calculated by the coordination node 2 or the data node that executes the update operation of the data table D according to the distribution key class ID hash algorithm and sent to the corresponding data node to perform the update operation.

[0390] When a data node updates data in the global secondary index d, the update operation is divided into two steps: deleting the old tuple and inserting the new tuple. First, the old tuple (12, 500132, Xiao Wang, location information, version information, partition information) is deleted, and then the new tuple (12, 500132, Xiao Li, location information, location information_new, version information_new, partition information_new) is inserted. In particular, when deleting the old tuple, the second DELETE operation scenario described above may occur: the corresponding tuple cannot be found in the global secondary index d. The corresponding handling method is the same as above and will not be repeated here.

[0391] After the global secondary index d is created, the data rows in table D that are updated during the creation of the global secondary index d will also be updated accordingly, and the data will remain consistent.

[0392] 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 the 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 in the system table to TRUE. After confirming the feedback from all other nodes, coordination node 1 sets its own metadata version to public. Coordination 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.

[0393] 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 shown in Figure 14. The global secondary index d is sharded into shard 1 of the global secondary index d (containing data of classid [13, 12, ...]), shard 2 of the global secondary index d (containing data of classid [11, 9, ...]), and shard 3 of the global secondary index d (containing data of classid [8, 7, ...]). Shard 1 of the global secondary index d is stored on data node 1, shard 2 of the global secondary index d is stored on data node 2, and shard 3 of the global secondary index d is stored on data node 3.

[0394] As shown in Figure 13, the shards of global secondary index d are all sorted by the user-defined index key classid. This allows users to quickly find the desired data based on classid when searching based on global secondary index d.

[0395] 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 achieving global consistency under the metadata non-asynchronous (synchronous) update mechanism. In this way, the high concurrency performance of the distributed system can be guaranteed without introducing a third-party node / tool ​​that already bears a high concurrent access load 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, without hindering the normal execution of the user's DML transaction. The architecture design is simple and low-cost, and does not introduce a third-party node / tool ​​to coordinate the metadata update. 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 in the index data. While ensuring data consistency, the coordination node waits until all nodes have normal feedback before continuing the process, without hindering the normal execution of the user's DML transaction, thus also ensuring high availability.

[0396] It is understandable that, in order to implement the above functions, the coordination node includes hardware and / or software modules that perform the corresponding functions. 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 this application.

[0397] In this embodiment, the coordination node can be divided into functional modules based on the above-described method examples. For example, each functional module can be divided into corresponding functional modules, or two or more functions can be integrated into a single processing module. The above-mentioned integrated modules can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents a logical functional division. In actual implementation, other division methods may be used.

[0398] 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 and is used to execute the functions or steps executed by the coordination node in the above method embodiment.

[0399] The embodiment of the present application further provides a coordination node in a distributed system, the coordination node including the above-mentioned index creation device. Optionally, the coordination node can be an independent server or a virtual machine in the server.

[0400] 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 via a line. The interface circuit can read instructions stored in a 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 coordinating node in the above-mentioned method embodiment. Of course, the chip system can also include other discrete components, which are not specifically limited in the present application.

[0401] 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 coordination node in the above-mentioned method embodiment.

[0402] 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.

[0403] 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.

[0404] In the several embodiments provided in this 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 merely schematic. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, 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.

[0405] The units described as separate components may or may not be physically separate, 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 places. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0406] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0407] 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 and includes several instructions for enabling a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0408] The above content is only a specific embodiment of this application, but the scope of protection of this application is not limited to this. Any changes or replacements within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection 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, wherein 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, including: 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, notifying the multiple other nodes to create and initialize metadata of the global secondary index, and setting 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 includes a coordination 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

Patent Citations

  • Index creating method and device in distributed system

    CN119357179A

  • Index updating method, system and related device

    CN109144994A

  • A HBase secondary index system and method based on Elastcisearch

    CN109299102A

  • Global secondary indexing method and device for distributed database

    CN113868251A

  • Index adding method and device, equipment and storage medium

    CN114661738A