Data writing method and device, electronic equipment and storage medium
By requesting lock resources from the second node and modifying the index split state when the local lock mode of the first node does not meet the target lock mode, the problem of low data writing efficiency caused by broadcast messages by the server in the cluster is solved, and data read and write performance is improved and integrity guaranteed.
Patent Information
- Application Number
- CN202410181789.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-18
- Publication Date
- 2025-08-19
AI Technical Summary
Servers in the cluster have low data writing efficiency due to broadcast messages preventing index splitting.
When the local lock mode of the first node does not meet the target lock mode, a lock resource acquisition request is sent to the second node, and after receiving the response, the split state of the index is being split, the index split is performed based on the target lock to avoid broadcasting messages.
Improves the read and write performance and efficiency of data, ensuring the integrity and consistency of data writing.
Smart Images

Figure CN120508240A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data writing method, device, electronic device, and storage medium. Background Art
[0002] Currently, when a server runs out of storage space on a page used to store data, the server triggers an index split. Specifically, the server requests a new page, which stores the data alongside the previous page.
[0003] When the server triggers an index split, it will broadcast a related message (also called a broadcast message) to other servers in the cluster to prevent other servers in the cluster from triggering an index split at the same time.
[0004] However, in the above method, in order to prevent other servers from triggering the index splitting process at the same time, there may be a large number of broadcast messages between the servers in the cluster, resulting in low data writing efficiency. Summary of the Invention
[0005] The present application provides a data writing method, device, electronic device and storage medium, which solves the technical problem that each server in a cluster avoids triggering index splitting at the same time through a large number of broadcast messages, thereby resulting in low data writing efficiency.
[0006] In a first aspect, a data writing method is provided, which is applied to a first node, and the method includes: first, when the lock mode of the local lock of the first node does not meet the lock mode of the target lock (that is, the lock resource for which the first node requests a preset operation on the index), the first node can send a lock resource acquisition request to the second node, that is, request to obtain the target lock; thereafter, when the split status of the index in the third node is to stop splitting, the first node can receive a first lock resource acquisition response sent by the second node, that is, notify that the target lock is successfully acquired; finally, the first node can modify the split status of the index in the first node to splitting, and perform index splitting based on the target lock.
[0007] In the present application, when the lock mode of the local lock of the first node does not meet the lock mode of the target lock, it means that the lock mode of the lock (i.e., the local lock) that the first node can use locally does not meet the lock mode of the lock (i.e., the target lock) corresponding to the preset operation requested by the first node for the index, that is, the first node cannot perform the preset operation on the index based on the target lock (or local lock). At this time, the first node can send a lock resource acquisition request to the second node, that is, request to obtain the target lock. Finally, after receiving the first lock resource acquisition response sent by the second node, the first node can modify the split state of the index in the first node to splitting, and perform index splitting based on the target lock. In this way, the first node can conveniently and quickly perform read and write operations on the data based on the target lock, which can improve the read and write performance of the data.
[0008] Optionally, before sending the lock resource acquisition request to the second node, the method also includes: when the lock mode of the local lock of the first node meets the lock mode of the target lock and the lock mode of the target lock is an exclusive lock, the first node modifies the split status of the index in the first node to splitting, and performs index splitting based on the target lock.
[0009] In this application, when the lock mode of the local lock of the first node meets the lock mode of the target lock, and the lock mode of the target lock is an exclusive lock, it means that the lock mode of the lock (i.e., the local lock) that the first node can use locally is the same as the lock mode of the lock (i.e., the target lock) corresponding to the preset operation requested by the first node for the index. At this time, the first node can modify the split state of the index in the first node to be splitting, which is used to indicate that the first node is performing the preset operation on the index and performing index splitting based on the target lock. This can avoid other nodes in the cluster from triggering index splitting at the same time without broadcasting messages, thereby improving the efficiency of data writing.
[0010] Optionally, the above-mentioned preset operation is a write operation, and the above-mentioned index splitting based on the target lock may specifically include: performing a splitting operation on the current page of the target data to obtain a target page, where the target data is the data corresponding to the index; and performing the write operation on the target data in the current page and the target page based on the target lock.
[0011] In this application, the first node can perform a split operation on the current page of the target data corresponding to the index to obtain the target page, and perform a write operation on the target data in the current page and the target page based on the target lock, which can effectively complete the writing process of the target data and improve the effectiveness of data writing.
[0012] Optionally, the method further includes: when there are no remaining pages in the current space of the target data, performing a memory request operation to obtain the current page.
[0013] In this application, when there are no remaining pages in the current space of the target data, it means that there is no page (or storage area) in the current space that can realize the writing process of the target data. At this time, the first node can perform a memory request operation, that is, expand the current space to increase the size of the current space. In this way, the first node can obtain the current page, thereby triggering the index split. This can ensure the integrity of the data written.
[0014] Optionally, before acquiring the current page, the method further includes: performing a release operation on the target lock; after acquiring the current page, the method further includes: performing a lock operation on the index based on the target lock.
[0015] In this application, since the first node is the holder of the target lock at this time, when other nodes need to perform a read operation on the index, the background is in a waiting (or stuck) state. Before the first node obtains the current page, since it does not affect the process of data writing by the first node, in order to improve the reading performance, the first node can perform a release operation on the target lock so that other nodes can perform a read operation on the index. After the first node obtains the current page, the writing process of the target data can be started. At this time, the first node performs a locking operation (or adds a target lock) on the index based on the target lock, that is, the first node can implement the writing process of the target data based on the target lock, thereby ensuring the validity of the data write.
[0016] Optionally, after the above-mentioned index splitting is performed based on the target lock, the method also includes: generating a second identifier of the index, the priority of the second identifier is higher than the priority of the first identifier of the index, the first identifier being the identifier of the index before the first node performs the splitting operation on the current page; broadcasting the second identifier of the index.
[0017] In this application, for an index, the first node can broadcast the higher-priority identifier of the index so that other nodes in the cluster can obtain the latest higher-priority identifier of the index, thereby avoiding other nodes from obtaining the old lower-priority identifier of the index, that is, other nodes can perform related operations on the index based on the latest and correct identifier, thereby being able to perform read and write operations on the latest data, ensuring data consistency.
[0018] Optionally, after executing the index split based on the target lock, the method further includes: modifying the split state of the index in the first node to stop splitting; executing a release operation on the target lock;
[0019] In this application, the first node modifies the split state of the index in the first node to stop splitting, and performs a release operation on the target lock, so that other nodes in the cluster can perform data read and write operations on the index based on the target lock, which can improve the efficiency of data migration.
[0020] Optionally, the method further includes receiving a second lock resource acquisition response sent by the second node, where the second lock resource acquisition response is used to notify the target lock acquisition failure.
[0021] In this application, after receiving the second lock resource acquisition response, the first node can determine that the target lock acquisition has failed, which can avoid the node from waiting in vain during the lock resource acquisition process and improve resource utilization.
[0022] In the second aspect, a data writing method is provided, which is applied to a third node. The method includes: first, the third node receives a lock resource release notification sent by the second node, that is, notifies the third node to perform a release operation on the target lock (that is, the lock resource that the first node requests to perform a preset operation on the index); then the third node can determine the split status of the index; finally, when the split status of the index in the third node is to stop splitting, the third node can send a first lock resource release response to the second node, that is, notify the successful release of the target lock.
[0023] In the present application, when the split status of the index in the third node is stopped splitting, it means that no node is currently performing index splitting, which can also be understood as no node is performing a write operation based on the target lock. At this time, the third node can perform a release operation on the target lock and send a first lock resource release response to the second node, that is, notifying the third node that the target lock has been successfully released. Thus, the second node can send a first lock resource acquisition response to the first node, that is, notifying that the target lock has been successfully acquired. In this way, the third node can accurately and effectively release the target lock, so that the first node can conveniently and quickly perform read and write operations on the data based on the target lock, which can improve the read and write performance of the data.
[0024] Optionally, the method also includes: when the split status of the index in the third node is splitting, the third node can determine whether the lock mode of the target lock is an exclusive lock; when the lock mode of the target lock is an exclusive lock, the third node sends a second lock resource release response to the second node, that is, notifies the second node that the release of the target lock fails.
[0025] In this application, when the lock mode of the target lock is an exclusive lock, it indicates that the first node requests a write operation on the index. Since the split status of the index in the third node is splitting, that is, the third node is performing index splitting (or data writing), the third node will not release the target lock at this time, that is, the target lock is still in a locked state for the third node. In this way, the third node can send a second lock resource release response to the second node, that is, notify the target lock release failure. This can ensure that only one node can perform index splitting, thereby improving the accuracy of data writing.
[0026] Optionally, the method further includes: when the split status of the index in the third node is stop splitting, the third node may broadcast a target identifier, where the target identifier is an identifier with the highest priority among the identifiers of the index.
[0027] In this application, an index can correspond to one or more identifiers (or version numbers). The target identifier with the highest priority is the latest, correct identifier corresponding to the index. The third node broadcasts this target identifier to prevent other nodes in the cluster from obtaining lower-priority, incorrect identifiers, further preventing them from obtaining erroneous, old data, thereby ensuring the validity and consistency of data access.
[0028] It is understood that the methods described in the first and second aspects can be performed by an electronic device, which can be a terminal, an apparatus including a terminal, or a chip within a terminal. Alternatively, the electronic device can be a network device, an apparatus including a network device, or a chip within a network device. For ease of understanding, the following description uses electronic device execution as an example.
[0029] In a third aspect, a data writing device is provided, which is applied to a first node. The device includes a sending module, a receiving module, and a processing module; the sending module is used to send a lock resource acquisition request to a second node when the lock mode of the local lock of the first node does not meet the lock mode of the target lock, the lock resource acquisition request is used to request the acquisition of the target lock, and the target lock is the lock resource requested by the first node to perform a preset operation on the index; the receiving module is used to receive a first lock resource acquisition response sent by the second node when the split status of the index in the third node is stopped splitting, the first lock resource acquisition response is used to notify the target lock that the acquisition is successful, and the third node is the previous node that performed the preset operation on the index; the processing module is used to modify the split status of the index in the first node to splitting, and perform index splitting based on the target lock.
[0030] Optionally, the processing module is also used to modify the split state of the index in the first node to splitting when the lock mode of the local lock of the first node meets the lock mode of the target lock and the lock mode of the target lock is an exclusive lock, and perform index splitting based on the target lock.
[0031] Optionally, the above-mentioned preset operation is a write operation; the processing module is specifically used to perform a split operation on the current page of the target data to obtain a target page, and the target data is the data corresponding to the index; the processing module is also specifically used to perform the write operation on the target data in the current page and the target page based on the target lock.
[0032] Optionally, the processing module is further configured to execute a memory request operation to obtain the current page when there are no remaining pages in the current space of the target data.
[0033] Optionally, the processing module is further configured to perform a release operation on the target lock before acquiring the current page; and the processing module is further configured to perform a lock operation on the index based on the target lock after acquiring the current page.
[0034] Optionally, the device also includes a broadcast module; the processing module is also used to generate a second identifier for the index, the priority of the second identifier is higher than the priority of the first identifier of the index, and the first identifier is the identifier of the index before the first node performs a split operation on the current page; the broadcast module is used to broadcast the second identifier of the index.
[0035] Optionally, the processing module is further used to modify the split state of the index in the first node to stop splitting; the processing module is further used to perform a release operation on the target lock.
[0036] Optionally, the receiving module is further configured to receive a second lock resource acquisition response sent by the second node, where the second lock resource acquisition response is used to notify the target lock acquisition failure.
[0037] In addition, the technical effects of the data writing device described in the third aspect can refer to the technical effects of the method described in the first aspect, and will not be repeated here.
[0038] In a fourth aspect, a data writing device is provided, which is applied to a third node. The device includes: a receiving module and a sending module; the receiving module is configured to receive a lock resource release notification sent by a second node, the lock resource release notification including an identifier of a target lock, and the lock resource release notification is configured to notify the third node to perform a release operation on the target lock, where the target lock is a lock resource for which the first node requested a preset operation on the index; and the sending module is configured to send a first lock resource release response to the second node when the split status of the index in the third node is stop splitting, the first lock resource release response being configured to notify the second node of the successful release of the target lock.
[0039] Optionally, the device also includes a determination module; the determination module is used to determine whether the lock mode of the target lock is an exclusive lock when the split status of the index in the third node is splitting; the sending module is also used to send a second lock resource release response to the second node when the lock mode of the target lock is an exclusive lock, and the second lock resource release response is used to notify the target lock that the release fails.
[0040] Optionally, the device further includes a broadcast module; the broadcast module is configured to broadcast a target identifier when the split state of the index in the third node is stop splitting, where the target identifier is the identifier with the highest priority among the identifiers of the index.
[0041] In addition, the technical effects of the data writing device described in the fourth aspect can refer to the technical effects of the method described in the first aspect, and will not be repeated here.
[0042] In a fifth aspect, a data writing device is provided. The data writing device includes: a module for executing the method described in the first aspect or the method described in the second aspect, such as a transceiver module and a processing module. For example, the transceiver module is used to perform the transceiver function of the data writing device, and the processing module is used to perform functions of the data writing device other than the transceiver function.
[0043] Optionally, the transceiver module may include a sending module and a receiving module, wherein the sending module is used to implement the sending function of the data writing device described in the third aspect or the data writing device described in the fourth aspect, and the receiving module is used to implement the receiving function of the data writing device described in the third aspect or the data writing device described in the fourth aspect.
[0044] Optionally, the data writing device described in the fifth aspect may further include a storage module, wherein the storage module stores a program or instruction. When the processing module executes the program or instruction, the data writing device may execute the method described in the first aspect or the method described in the second aspect.
[0045] It can be understood that the data writing device described in the fifth aspect can be a terminal or a network device, or a chip (system) or other parts or components that can be set in the terminal or network device, or a device that includes a terminal or a network device. This application does not limit this.
[0046] In addition, the technical effects of the data writing device described in the fifth aspect can refer to the technical effects of the other aspects mentioned above and will not be repeated here.
[0047] In a sixth aspect, a data writing device is provided, which includes a processor configured to execute the method described in the first aspect or the method described in the second aspect.
[0048] In one possible design solution, the data writing device described in the sixth aspect may further include a transceiver. The transceiver may be a transceiver circuit or an interface circuit. The transceiver may be used for the data writing device described in the sixth aspect to communicate with other devices.
[0049] In one possible design, the data writing device described in the sixth aspect may further include a memory. The memory may be integrated with the processor or provided separately. The memory may be used to store the computer program and / or data involved in the method described in the first aspect or the method described in the second aspect.
[0050] In an embodiment of the present application, the communication device described in the sixth aspect may be the terminal or network device described in the first aspect or the second aspect, or a chip (system) or other parts or components that can be set in the terminal or network device, or a device that includes the terminal or network device.
[0051] In addition, the technical effects of the data writing device described in the sixth aspect can refer to the technical effects of the method described in the first aspect or the method described in the second aspect, and will not be repeated here.
[0052] In a seventh aspect, a data writing device is provided. The communication device includes: a processor coupled to a memory, the processor being configured to execute a computer program stored in the memory, so that the data writing device executes the method described in the first aspect or the method described in the second aspect.
[0053] In one possible design solution, the data writing device described in the seventh aspect may further include a transceiver. The transceiver may be a transceiver circuit or an interface circuit. The transceiver may be used for the data writing device described in the seventh aspect to communicate with other devices.
[0054] In an embodiment of the present application, the data writing device described in the seventh aspect can be the terminal or network device described in the first aspect or the second aspect, or a chip (system) or other parts or components that can be set in the terminal or network device, or a device that includes the terminal or network device.
[0055] In addition, the technical effects of the data writing device described in the seventh aspect can refer to the technical effects of the method described in the first aspect or the second aspect, and will not be repeated here.
[0056] In an eighth aspect, a data writing device is provided, comprising: a processor and a memory; the memory is used to store a computer program, and when the processor executes the computer program, the data writing device executes the method described in the first aspect or the method described in the second aspect.
[0057] In one possible design solution, the data writing device described in the eighth aspect may further include a transceiver. The transceiver may be a transceiver circuit or an interface circuit. The transceiver may be used for the data writing device described in the eighth aspect to communicate with other devices.
[0058] In an embodiment of the present application, the data writing device described in the eighth aspect may be the terminal or network device described in the first aspect or the second aspect, or a chip (system) or other parts or components that can be set in the terminal or network device, or a device that includes the terminal or network device.
[0059] In addition, the technical effects of the data writing device described in the eighth aspect can refer to the technical effects of the method described in the first aspect or the second aspect, and will not be repeated here.
[0060] In a ninth aspect, a computer-readable storage medium is provided, comprising: a computer program or instructions; when the computer program or instructions are run on an electronic device, the electronic device executes the method described in the first aspect or the method described in the second aspect.
[0061] In a tenth aspect, a computer program product is provided, comprising a computer program or instructions, which, when executed on an electronic device, causes the electronic device to execute the method described in the first aspect or the method described in the second aspect.
[0062] It will be understood that the above general description and the following detailed description are merely exemplary and explanatory and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A schematic diagram of a process for triggering index splitting provided in an embodiment of the present application is shown;
[0064] Figure 2 A schematic diagram of a network architecture of a data writing system provided in an embodiment of the present application is shown;
[0065] Figure 3 A schematic diagram of a data writing method according to an embodiment of the present application is shown;
[0066] Figure 4 A schematic diagram showing a flow chart of another data writing method provided in an embodiment of the present application is shown;
[0067] Figure 5 A schematic diagram showing a flow chart of another data writing method provided in an embodiment of the present application is shown;
[0068] Figure 6 A schematic diagram showing a flow chart of another data writing method provided in an embodiment of the present application is shown;
[0069] Figure 7 A schematic diagram showing a flow chart of another data writing method provided in an embodiment of the present application is shown;
[0070] Figure 8A schematic diagram showing the improvement effect of IPS under different concurrency conditions provided by an embodiment of the present application is shown;
[0071] Figure 9 A schematic structural diagram of a data writing device provided in an embodiment of the present application is shown;
[0072] Figure 10 A schematic structural diagram of another data writing device provided in an embodiment of the present application is shown;
[0073] Figure 11 A structural schematic diagram of another data writing device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0074] To facilitate understanding of the solutions provided in the embodiments of the present application, some concepts involved in the present application are explained before introducing the solutions provided in the embodiments of the present application.
[0075] A distributed lock service (DLS) is a locking mechanism used in distributed systems that allows synchronization between multiple nodes to prevent simultaneous access and modification of shared resources or data. This service provides a reliable way to control concurrent access to data, thereby avoiding concurrency issues such as data inconsistency.
[0076] A lock is a synchronization mechanism used to enforce access restrictions on shared resources or data to ensure data integrity and consistency in a concurrent environment. The primary function of a lock is to prevent multiple threads from accessing and modifying shared resources or data simultaneously, thus avoiding data conflicts and inconsistencies.
[0077] Lock resources are mechanisms used to control concurrent access to shared resources or data. In a multithreaded or concurrent environment, multiple threads may access or modify shared resources simultaneously, potentially leading to data conflicts and inconsistencies. To address this, lock resources can be introduced to control access to shared resources or data.
[0078] A local lock is a mechanism that controls access to shared resources or data by multiple threads and is typically used in single-process systems. In a single-process system, when multiple threads need to access a shared resource or data simultaneously, synchronization is necessary to prevent data inconsistency or corruption. To ensure that only one thread can execute a block of code at a time, a marker must be set somewhere. This marker is visible to all threads. If other threads detect a marker, they must wait until the thread holding the marker completes its synchronization block and unmarks it before attempting to set the marker again. This marker can be understood as a lock or local lock.
[0079] Alternatively, whether multiple threads can acquire the same lock can be divided into: exclusive locks and shared locks. That is, in this application, the lock mode of a lock may include but is not limited to exclusive locks and shared locks.
[0080] An exclusive lock, also known as an exclusive lock or write lock, can be held by only one thread or process at a time. This allows only one thread or process to read or write to a resource at a time; other threads or processes must wait until that thread or process releases the lock before they can proceed. A shared lock, also known as a read lock, can be held by multiple threads. Multiple threads or processes can simultaneously obtain a shared lock to read a resource, but only one thread or process can obtain an exclusive lock to modify it. This ensures that multiple threads or processes can read a resource simultaneously, but require exclusive access to modify it, thus guaranteeing data consistency and integrity.
[0081] An index is a data structure used to quickly retrieve data from a database table. An index can be thought of as a pointer to one or more rows in a table, allowing the database system to quickly locate the required data without traversing the entire table row by row. An index can consist of one or more indexes, and a collection of multiple indexes can be referred to as an index block.
[0082] Index splitting, also known as index or index block splitting, occurs when a data manipulation language (DML) command modifies the data in the storage space indicated by an index or index block, but the original storage space does not have enough space to accommodate the newly modified data. In this application, index splitting includes two splitting states: splitting state and stopped splitting. The splitting state can indicate that the index block is splitting, while the stopped splitting state indicates that the index block has stopped splitting.
[0083] In traditional clustered relational databases, a single node (e.g., a server) can store (or write) a large amount of indexed data. In data migration scenarios, the server can migrate its stored data to other servers within the cluster or to other clusters. To prevent the server from triggering an index split simultaneously with other servers in the cluster, the server broadcasts a related message (also known as a broadcast message) to the other servers in the cluster.
[0084] In an optional implementation, the process of triggering index splitting on a node in the cluster (for example, node 0) can refer to Figure 1 , the process may specifically include S101-S109.
[0085] S101. Node 0 adds an exclusive lock to the index through DLS.
[0086] In combination with the description of the above embodiment, it should be understood that the exclusive lock is a write lock, and node 0 can implement a write operation on the index (or the data corresponding to the index) by adding an exclusive lock to the index.
[0087] Optionally, before S101 above, if the exclusive lock does not exist in node 0, node 0 may obtain the exclusive lock from another node (eg, node 1) in the cluster.
[0088] S102: Node 0 changes the split status of the index to "splitting" and synchronizes the split status of the index to other nodes in the cluster through broadcasting.
[0089] It should be understood that Node 0 broadcasting the index split status to other nodes in the cluster is called broadcasting the index split status within the cluster. This allows other nodes in the cluster to obtain the index split status. These other nodes can determine that the index split status is currently splitting, which can prevent these other nodes from triggering the index split process. These other nodes include Node 1.
[0090] S103. Node 1 obtains the split status of the index broadcast by node 0.
[0091] S104. Node 1 sends a first confirmation message to node 0.
[0092] The first confirmation message is used to notify that the split status of the index has been confirmed to be splitting.
[0093] S105. Node 0 performs a split operation on the page where the index is located.
[0094] S106. Node 0 changes the split status of the index to stop splitting, and synchronizes the split status of the index to other nodes in the cluster through broadcasting.
[0095] It should be understood that at this time, other nodes in the cluster (including node 1) can determine that the split state of the index at this time is to stop splitting.
[0096] S107 , node 1 obtains the split status of the index broadcast by node 0.
[0097] S108. Node 1 sends a second confirmation message to node 0.
[0098] The second confirmation message is used to notify that the split status of the index has been confirmed to be stopped.
[0099] S109. Node 0 releases the exclusive lock of the index.
[0100] It is understandable that after node 0 releases the exclusive lock, other nodes in the cluster (such as node 1) can use the exclusive lock to trigger index splitting to implement the data writing process.
[0101] During the above process, there may be a large number of broadcast messages (or communication processes, including node 0 broadcasting the index split status and node 1 sending a confirmation message to node 0) to prevent all nodes in the cluster from triggering index splitting at the same time, resulting in low data writing efficiency and greatly increased data migration time.
[0102] Based on this, an embodiment of the present application provides a data writing method, in which, when the lock mode of the local lock of the first node does not meet the lock mode of the target lock, it indicates that the lock mode of the lock (i.e., the local lock) that the first node can use locally does not meet the lock mode of the lock (i.e., the target lock) corresponding to the preset operation requested by the first node for the index, that is, the first node cannot perform the preset operation on the index based on the target lock (or local lock). At this time, the first node can send a lock resource acquisition request to the second node, that is, request to obtain the target lock. Finally, after receiving the first lock resource acquisition response sent by the second node, the first node can modify the split state of the index in the first node to splitting, and perform index splitting based on the target lock. In this way, the first node can conveniently and quickly perform read and write operations on the data based on the target lock, which can improve the read and write performance of the data.
[0103] The data writing method, apparatus, electronic device, and storage medium provided in the embodiments of this application are applicable to database scenarios, including but not limited to data migration, index splitting, and data reading and writing. When an electronic device acquires a target lock, it can perform index splitting based on the target lock using the data writing method provided in the embodiments of this application.
[0104] In order to enable ordinary people in the art to better understand the technical solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0105] It is understood that the terms "first," "second," and the like in the specification and claims of this application and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments of the application described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0106] It will also be understood that the term “comprising” indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements and / or components.
[0107] The data writing method, device, electronic device and storage medium provided in the embodiments of the present application can be applied to a data writing system. Figure 2 As shown, the data writing system includes node 201, node 202 and node 203. Generally, in practical applications, the connection between the above nodes (or devices) can be a wireless connection. In order to conveniently and intuitively represent the connection relationship between the nodes, Figure 2 Solid lines are used to indicate.
[0108] Node 201 may send a lock resource acquisition request to node 202 , where the lock resource acquisition request is used to request acquisition of a target lock.
[0109] Node 202 may send a lock resource release notification to node 203 , where the lock resource release notification is used to notify node 203 to perform a release operation on the target lock.
[0110] Node 203 may send a first lock resource release response to node 202 , where the first lock resource release response is used to notify that the target lock is successfully released.
[0111] In the embodiment of the present application, for a lock resource (such as a target lock), the nodes included in the above-mentioned data write system may have different roles based on the target lock. For example, node 201 can be a visitor or requester (requester) of the target lock, for obtaining the right to use the target lock. Node 202 can be the manager (master) of the target lock, for deciding and coordinating which node has the right to use the target lock. Node 203 can be the holder (owner) of the target lock, for indicating that the node 203 has obtained the right to use the target lock.
[0112] In one example, the electronic device (including the above-mentioned node 201, node 202 and node 203) that executes the index splitting method provided in an embodiment of the present application can be a terminal, which can also be called user equipment (UE), access terminal, subscriber unit (subscriber unit), user station, mobile station (MS), mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent or user device. The terminal in the embodiments of the present application can be a mobile phone, a cellular phone, a smart phone, a tablet computer, a wireless data card, a personal digital assistant (PDA), a wireless modem, a handheld device (handset), a laptop computer, a machine type communication (MTC) terminal, a computer with wireless transceiver function, a virtual reality (VR) terminal, an augmented reality (AR) terminal, a smart home device (for example, a refrigerator, a television, an air conditioner, an electric meter, etc.), an intelligent robot, a robotic arm, a workshop equipment, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical care, a wireless terminal in a smart grid, a wireless terminal in transportation safety, a wireless terminal in a smart city, a wireless terminal in a smart home, a vehicle-mounted terminal, a roadside unit with terminal function, or a wireless terminal in a smart city. The terminal of the present application may also be an on-board module, on-board module, on-board component, on-board chip or on-board unit built into a vehicle as one or more components or units. The terminal may also be other devices with terminal functions, for example, the terminal may also be a device that functions as a terminal in device-to-device (D2D) communication.
[0113] The embodiments of this application do not limit the device form factor of the terminal. The device used to implement the terminal's function can be a terminal; it can also be a device that supports the terminal in implementing the function, such as a chip system. The device can be installed in the terminal or used in conjunction with the terminal. In the embodiments of this application, the chip system can be composed of a chip or include a chip and other discrete components.
[0114] In another example, the above-mentioned electronic device can also be a server, which can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, network acceleration services (content delivery network, CDN), as well as big data and artificial intelligence platforms.
[0115] like Figure 3 As shown, the data writing method provided in the embodiment of the present application may include S301-S302.
[0116] S301: When the lock mode of the local lock of the first node does not meet the lock mode of the target lock, the first node applies for a lock resource with an exclusive lock mode.
[0117] S302. When the lock mode of the local lock of the first node meets the lock mode of the target lock and the lock mode of the target lock is an exclusive lock, the first node modifies the split state of the index in the first node to splitting and performs index splitting based on the target lock.
[0118] The relevant description of the local lock can be referred to above and will not be repeated here.
[0119] The target lock is a lock resource requested by the first node to perform a preset operation on the index.
[0120] It should be understood that the index corresponds to the resource or data stored (or written) in the first node. The first node's request to perform a preset operation on the index can also be understood as the first node's request to perform a preset operation on the data corresponding to the index.
[0121] It is understandable that any node in the cluster (or cluster range) can determine and modify the split state of the index in the node when performing a preset operation on the index. When the split state is stopped, other nodes in the cluster can modify the split state to splitting, thereby triggering index splitting or implementing data writing. When the split state is splitting, it means that there is a node (or the current node) that is performing index splitting. In this case, other nodes cannot modify the split state and cannot trigger index splitting.
[0122] Optionally, the preset operation may be a read operation or a write operation, wherein the write operation may include but is not limited to index splitting.
[0123] In the embodiment of the present application, the first node may first apply a local lock to the index within the first node, which can also be understood as performing a locking operation on the index based on the local lock. Thereafter, it is determined whether the lock mode of the local lock satisfies the lock mode of the target lock.
[0124] When the lock mode of the local lock of the first node meets the lock mode of the target lock, it means that the lock mode of the lock that the first node can use locally (i.e., the local lock) is the same as the lock mode of the lock resource (i.e., the target lock) corresponding to the preset operation requested by the first node for the index, that is, the first node can perform the preset operation on the index based on the target lock (or local lock).
[0125] In addition, when the lock mode of the target lock is exclusive, it indicates that the preset operation is a write operation, specifically, the first node requests a write operation on the index. In this case, the first node can modify the split status of the index on the first node to "splitting", which can ensure that only one node (i.e., the first node) currently performs the write operation on the index, preventing other nodes in the cluster from performing write operations on the index simultaneously.
[0126] It can be understood that there can only be one node triggering index splitting, which means that an index (or the target data corresponding to the index) can only be written to by one node at the same time, and other nodes cannot perform write operations on the index (or target data), that is, index splitting cannot be triggered.
[0127] In one example, when the third node is the owner of the target lock, the third node can perform a preset operation on the index. If the split status of the index on the third node is "splitting in progress", the first node, as the requester of the target lock, cannot use the target lock, that is, cannot trigger the index split.
[0128] Specifically, the implementation method can refer to the following Figure 7 The corresponding embodiments are described.
[0129] In an embodiment of the present application, when the lock mode of the local lock of the first node satisfies the lock mode of the target lock, and the lock mode of the target lock is an exclusive lock, it indicates that the lock mode of the lock (i.e., the local lock) that the first node can use locally is the same as the lock mode of the lock (i.e., the target lock) corresponding to the preset operation requested by the first node for the index. At this time, the first node can modify the split state of the index in the first node to splitting, which is used to indicate that the first node is performing the preset operation on the index and performing index splitting based on the target lock. This eliminates the need to broadcast messages and can also prevent other nodes in the cluster from triggering index splitting at the same time, thereby improving the efficiency of data writing.
[0130] Combine Figure 3 ,like Figure 4 As shown, in one implementation of an embodiment of the present application, the first node performs index splitting based on the target lock, which may specifically include S3021-S3022.
[0131] S3021. The first node performs a split operation on the current page of the target data to obtain a target page.
[0132] The target data is the data corresponding to the above index.
[0133] S3022. The first node performs a write operation on the target data in the current page and the target page based on the target lock.
[0134] Specifically, when the first node determines that the current page cannot write all the data of the target data, it can apply for a new page (i.e., the target page). The first node will write (or translate) part of the data already written to the current page to the target page, so that the target data is written to the current page and the target page. This can also be understood as writing part of the target data to the current page and writing the rest of the target data to the target page.
[0135] In an embodiment of the present application, the first node can perform a split operation on the current page of the target data corresponding to the index to obtain the target page, and perform a write operation on the target data in the current page and the target page based on the target lock, which can effectively complete the writing process of the target data and improve the effectiveness of data writing.
[0136] In one implementation of the embodiment of the present application, before the current page is split, there may not be any page to write the target data. In this case, the first node needs to expand the space (or storage space) to be written to obtain the current page. Based on this, combined with Figure 4 ,like Figure 5 As shown, the data writing method provided in the embodiment of the present application also includes S303.
[0137] S303: When there are no remaining pages in the current space of the target data, the first node performs a memory request operation to obtain the current page.
[0138] It should be understood that the current space is a storage space used to write (or store) target data. A space can be understood as a larger storage area. A space includes one or more pages, and a page can be understood as a smaller storage area.
[0139] For example, the size of a space may be 32M (megabytes), and the size of a page may be 8K (kilobytes). The embodiment of the present application does not specifically limit the size of a space and the size of a page.
[0140] In an embodiment of the present application, when there are no remaining pages in the current space of the target data, it indicates that there is no page (or storage area) in the current space that can implement the writing process of the target data. At this time, the first node can perform a memory request operation, that is, expand the current space to increase the size of the current space. In this way, the first node can obtain the current page, thereby triggering the index split. This can ensure the integrity of the data written.
[0141] It should be understood that read operations and write operations are mutually exclusive. Since the first node is the owner of the target lock at this time, when other nodes need to perform read operations on the index, the background is in a waiting (or stuck) state. Before the first node obtains the current page, since other nodes can perform read operations on the index without affecting the process of the first node writing data, in order to improve the reading performance, the first node can perform a release operation on the target lock so that other nodes can perform read operations on the index. Specifically, the implementation process is as follows Figure 6 As shown, before the first node obtains the current page, S304 may also be included.
[0142] S304: The first node performs a release operation on the target lock.
[0143] In the embodiment of the present application, the first node performing a release operation on the target lock can be understood as a lock release process in the first node.
[0144] Continue as Figure 6 As shown, after the first node obtains the current page, the data writing method provided in the embodiment of the present application also includes S305.
[0145] S305: The first node performs a locking operation on the index based on the target lock.
[0146] It is understood that the lock release process is performed before acquiring the current page (or writing data). After the first node acquires the current page, it can begin writing the target data. At this point, the first node performs a locking operation (or adds a target lock) on the index based on the target lock. This means that the first node can write the target data based on the target lock, thereby ensuring the validity of the data write.
[0147] In an embodiment of the present application, for each node in a server cluster (such as the above-mentioned data writing system), the same data and the index of the data need to remain consistent. Therefore, for an index, the first node can broadcast the higher-priority identifier of the index so that other nodes in the cluster can obtain the latest identifier of the index with a higher priority, thereby avoiding other nodes from obtaining the old identifier of the index with a lower priority, that is, other nodes can perform related operations on the index based on the latest and correct identifier. Specifically, the process may include the following steps A-B.
[0148] Step A: The first node generates a second identifier of the index.
[0149] The priority of the second identifier is higher than the priority of the first identifier of the index, and the first identifier is the identifier of the index before the first node performs a split operation on the current page.
[0150] In an optional implementation, the first node may first obtain the first identifier of the index, and perform a target operation (such as increasing the size of a number) on the first identifier, thereby obtaining the second identifier of the index.
[0151] Optionally, an identifier of an index may be a version number of the index, that is, the version number corresponding to the second identifier is higher than the version number corresponding to the first identifier.
[0152] Step B: The first node broadcasts the second identifier of the index.
[0153] Based on the above steps A and B, each node in the server cluster can perform read and write operations on the latest data, thereby ensuring data consistency.
[0154] Correspondingly, after the first node completes the index split, that is, after S302 is completed, the first node can also modify the index split status to stop splitting, so that the target lock can be released to other nodes based on the index split status, so that other nodes can execute the index split. Specifically, this process can refer to the following steps C-D:
[0155] Step C: The first node changes the split state of the index in the first node to stop splitting.
[0156] It should be understood that after the first node performs the write operation on the target data, the data writing (or index splitting) process of the first node has been completed. At this time, the first node can change the split state of the index to stop splitting, so that other nodes in the cluster can implement the data writing process.
[0157] It is understood that after the first node changes the index split status to "splitting in progress," the first node may not broadcast the index split status. After the first node changes the index split status to "stop splitting," the first node may also not broadcast the index split status. This effectively avoids a large number of broadcast messages (or communication processes) within the cluster that could affect data writing and data migration.
[0158] Optionally, for any node in the cluster, the index splitting state can be represented by true or false. Specifically, true is used to represent the index splitting state as splitting in progress, and false is used to represent the index splitting state as stopped.
[0159] Step D: The first node performs a release operation on the target lock.
[0160] It is understandable that after the first node releases the target lock, other nodes in the cluster can request and obtain the target lock, thereby implementing data read and write operations based on the target lock.
[0161] In this way, based on the above steps C-D, the first node can modify the split state of the index in the first node to stop splitting, and perform a release operation on the target lock, so that other nodes in the cluster can perform data read and write operations on the index based on the target lock, which can improve the efficiency of data migration.
[0162] In one implementation of the embodiment of the present application, the lock mode of the local lock of the first node may not meet the lock mode of the target lock. In this case, the first node can request the target lock manager (master) to obtain the target lock and the target lock usage rights, thereby implementing the process of writing data based on the target lock. Figure 7 As shown, the data writing method provided in the embodiment of the present application may further include S306-S315.
[0163] S306: When the lock mode of the local lock of the first node does not satisfy the lock mode of the target lock, the first node sends a lock resource acquisition request to the second node.
[0164] The lock resource acquisition request is used to request the acquisition of a target lock, where the target lock is a lock resource for which the first node requests to perform a preset operation on the index.
[0165] It should be understood that the lock resource acquisition request may include an identifier of the target lock, and the second node is the manager of the target lock.
[0166] It is understandable that if the lock mode of the local lock of the first node does not meet the lock mode of the target lock, it means that the lock mode of the lock that the first node can use locally (i.e., the local lock) does not meet the lock mode of the lock (i.e., the target lock) corresponding to the preset operation requested by the first node for the index, that is, the first node cannot perform the preset operation on the index based on the target lock (or local lock). At this time, the first node can send a lock resource acquisition request to the second node, that is, request to acquire the target lock.
[0167] In one case, the lock mode of the local lock of the first node is empty, that is, the local lock has neither a read function nor a write function, then the first node may determine that the lock mode of the local lock does not satisfy the lock mode of the target lock.
[0168] In another case, the lock mode of the local lock of the first node is an exclusive lock (or shared lock), and the lock mode of the target lock is a shared lock (or exclusive lock), that is, the lock mode of the local lock of the first node is different from the lock mode of the target lock, then the first node can determine that the lock mode of the local lock does not meet the lock mode of the target lock.
[0169] S307: The second node receives the lock resource acquisition request sent by the first node.
[0170] S308: The second node sends a lock resource release notification to the third node.
[0171] The lock resource release notification includes an identifier of a target lock, and is used to notify the third node to perform a release operation on the target lock.
[0172] In combination with the description of the above embodiment, it should be understood that the target lock is the lock resource for the above first node to request the preset operation on the index.
[0173] It is understood that after receiving the lock resource acquisition request, the second node can determine whether there is a lock conflict for the target lock, specifically whether the target lock is being used by another node. When the second node determines that the target lock is being used by a third node (i.e., the third node is currently the owner of the target lock), the second node sends a lock resource release notification to the third node, i.e., notifies the third node to perform a release operation on the target lock.
[0174] In an optional implementation, when there is no lock conflict for the target lock (ie, the target lock is not used by other nodes), the second node may send a first lock resource acquisition response to the first node, where the first lock resource acquisition response is used to notify that the target lock is successfully acquired.
[0175] S309: The third node receives the lock resource release notification sent by the second node.
[0176] S310. The third node determines the split status of the index.
[0177] The split status of the index can be either stopped or in progress.
[0178] S311: When the split status of the index in the third node is stop splitting, the third node sends a first lock resource release response to the second node.
[0179] The first lock resource release response is used to notify the successful release of the target lock.
[0180] It should be understood that since index splitting can only be performed on one node, when the index split status is "stop splitting", it means that no node is currently performing index splitting, which can also be understood as no node performing a write operation based on the target lock. At this time, the third node can perform a release operation on the target lock and send the first lock resource release response to the second node, notifying the third node that the target lock has been successfully released.
[0181] In an optional implementation, when the split status of the index in the third node is stop splitting, the third node may further broadcast a target identifier, where the target identifier is an identifier with the highest priority among the identifiers of the above index.
[0182] In conjunction with the description of the above embodiment, it should be understood that an index can correspond to one or more identifiers (or version numbers), and the target identifier with the highest priority is the latest, correct identifier corresponding to the index. The third node broadcasts this target identifier to prevent other nodes in the cluster from obtaining lower-priority, incorrect identifiers, further preventing these other nodes from obtaining erroneous, old data, thereby ensuring the validity and consistency of data access.
[0183] S312: The second node receives a first lock resource release response sent by the third node.
[0184] S313. The second node sends a first lock resource acquisition response to the first node.
[0185] The first lock resource acquisition response is used to notify that the target lock is acquired successfully.
[0186] S314. The first node receives a first lock resource acquisition response sent by the second node.
[0187] S315. The first node changes the splitting state of the index in the first node to splitting, and performs index splitting based on the target lock.
[0188] In the embodiment of the present application, if the lock mode of the local lock of the first node does not satisfy the lock mode of the target lock, it means that the lock mode of the lock that the first node can use locally (i.e., the local lock) does not satisfy the lock mode of the lock (i.e., the target lock) corresponding to the preset operation requested by the first node for the index, that is, the first node cannot perform the preset operation on the index based on the target lock (or local lock). In this case, the first node can send a lock resource acquisition request to the second node, that is, requesting to acquire the target lock.
[0189] Afterwards, the second node can send a lock resource release notification to the third node, that is, notify the third node to perform a release operation on the target lock. After receiving the lock resource release notification, the third node can determine the split status of the index. When the split status of the index in the third node is stop splitting, it means that no node is currently performing index splitting, which can also be understood as no node is performing a write operation based on the target lock. At this time, the third node can perform a release operation on the target lock and send a first lock resource release response to the second node, that is, notify the third node that the target lock has been successfully released. The second node can then send a first lock resource acquisition response to the first node, that is, notify that the target lock has been successfully acquired. That is, the third node can accurately and effectively release the target lock.
[0190] Finally, after receiving the first lock resource acquisition response from the second node, the first node can change the split status of the index on the first node to "splitting in progress" and perform the index split based on the target lock. This allows the first node to conveniently and quickly perform read and write operations on data based on the target lock, improving data read and write performance.
[0191] Continue as Figure 7 As shown, after the above S310, the data writing method provided by the embodiment of the present application may further include S316-S320.
[0192] S316: When the split status of the index in the third node is splitting, the third node determines whether the lock mode of the target lock is an exclusive lock.
[0193] It should be understood that when the split status of the index on the third node is "splitting", it indicates that a node (i.e., the third node) is currently performing an index split. At this time, the third node can determine whether the lock mode of the target lock is exclusive, that is, whether other nodes can perform the preset operation on the index.
[0194] S317: When the lock mode of the target lock is an exclusive lock, the third node sends a second lock resource release response to the second node.
[0195] The second lock resource acquisition response is used to notify the target lock request of failure.
[0196] It is understandable that when the lock mode of the target lock is an exclusive lock, it means that the data resource corresponding to the target lock is locked by the third node. The third node can perform write operations, index splitting operations, etc. on the data resource corresponding to the target lock, while other nodes, such as the first node, cannot perform write operations on the data resource. Since the index splitting state is splitting, that is, the third node is in the process of index splitting (or data writing), the third node will not release the target lock at this time, that is, the target lock is still in a locked state for the third node. In this way, the third node can send a second lock resource release response to the second node, that is, notify the target lock release failure.
[0197] In an optional implementation, when the lock mode of the target lock is a shared lock, it means that although the data resource corresponding to the target lock is locked by the third node and only the third node is allowed to modify the data resource corresponding to the target lock, the target lock cannot perform write operations, index splitting operations, etc. on the data resource corresponding to the target lock for other nodes, such as the first node, but can perform read and write operations. Although the split status of the index is splitting, the ongoing index splitting (or data writing) of the third node will not affect the first node's read operation on the index. At this time, the third node can also send a first lock resource release response to the second node, and then the second node can send a first lock resource acquisition response to the first node. Finally, after acquiring the target lock, the first node can perform a read operation on the target data based on the target lock.
[0198] S318. The second node receives a second lock resource release response sent by the third node.
[0199] S319: The second node sends a second lock resource acquisition response to the first node.
[0200] The second lock resource acquisition response is used to notify the target lock acquisition failure.
[0201] It should be understood that after receiving the second lock resource release response, the second node may determine that the target lock release failed, that is, the second node may determine that the first node cannot use the target lock or the first node does not have permission to use the target lock. At this time, the second node may send a second lock resource acquisition response to the first node, that is, notify the first node that the target lock acquisition failed.
[0202] S320: The first node receives a second lock resource acquisition response sent by the second node.
[0203] It is understood that after receiving the second lock resource acquisition response, the first node may determine that the target lock is currently unavailable, specifically that the preset operation cannot be performed on the index based on the target lock. The first node may then re-initiate the lock resource acquisition request to enable read and write operations on the target data.
[0204] In an embodiment of the present application, when the lock mode of the target lock is an exclusive lock, it indicates that the first node is requesting a write operation on the index. Furthermore, since the split status of the index in the first node is "splitting in progress," i.e., the third node is performing index splitting (or data writing), the third node will not release the target lock at this time, i.e., the target lock remains locked for the third node. In this way, the third node can send a second lock resource release response to the second node, notifying the second node that the target lock release has failed. This ensures that only one node can perform index splitting, thereby improving the accuracy of data writing.
[0205] Afterward, the second node can send a second lock resource acquisition response to the first node, notifying it of the target lock acquisition failure. Upon receiving this second lock resource acquisition response, the first node can determine that the target lock acquisition failed. This avoids ineffective waiting for nodes to acquire lock resources, improving resource utilization.
[0206] In the embodiment of the present application, in the scenario of data migration, the data writing method provided by the embodiment of the present application can greatly improve the performance of database migration data. For example, Figure 8 As shown in the figure, between 20 and 100 concurrency, the range of improvement in instructions per second (IPS) is between 10% and 65%. The lines before optimization refer to the IPS at different concurrency levels before the data writing method provided by the embodiment of the present application, while the lines after optimization refer to the IPS at different concurrency levels after the data writing method provided by the embodiment of the present application.
[0207] Specifically, 30 concurrency means that the number of concurrent users (or concurrent users) is 30, which means that 30 threads can currently perform data writing operations in the data table at the same time.
[0208] like Figure 8 As shown in the figure, under 30 concurrent connections, the IPS before optimization was 125,000, and the IPS after optimization was 180,000, with an improvement of 44%.
[0209] It is understandable that in order to implement the functions in the above embodiments, the electronic device includes hardware structures and / or software modules corresponding to the execution of each function. It should be readily apparent to those skilled in the art that, in combination with the units and method steps of each example described in the embodiments disclosed in this application, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application scenario and design constraints of the technical solution.
[0210] Combined with the above Figures 1 to 8, describes in detail the data writing method provided by this embodiment, and will now be combined with Figures 9-11 , describing the data writing device provided according to this embodiment.
[0211] This application also provides a data writing device, such as Figure 9 As shown, the data writing device 40 includes: a sending module 401 , a receiving module 402 and a processing module 403 .
[0212] Sending module 401 is used to send a lock resource acquisition request to the second node when the lock mode of the local lock of the first node does not meet the lock mode of the target lock. The lock resource acquisition request is used to request to obtain the target lock, which is the lock resource for the first node to request to perform a preset operation on the index.
[0213] Receiving module 402 is used to receive the first lock resource acquisition response sent by the second node when the split status of the index in the third node is stop splitting. The first lock resource acquisition response is used to notify the target lock that the acquisition is successful. The third node is the previous node that performs the preset operation on the index.
[0214] The processing module 403 is configured to modify the splitting state of the index in the first node to being split, and perform index splitting based on the target lock.
[0215] Optionally, the processing module 403 is also used to modify the split state of the index in the first node to splitting when the lock mode of the local lock of the first node meets the lock mode of the target lock and the lock mode of the target lock is an exclusive lock, and perform index splitting based on the target lock.
[0216] Optionally, the above-mentioned preset operation is a write operation.
[0217] The processing module 403 is specifically configured to perform a split operation on the current page of the target data to obtain a target page, where the target data is the data corresponding to the index.
[0218] The processing module 403 is further specifically configured to perform the write operation on the target data in the current page and the target page based on the target lock.
[0219] Optionally, the processing module 403 is further configured to execute a memory allocation operation to obtain the current page when there are no remaining pages in the current space of the target data.
[0220] Optionally, the processing module 403 is further configured to release the target lock before acquiring the current page.
[0221] The processing module 403 is further configured to perform a locking operation on the index based on the target lock after acquiring the current page.
[0222] Optionally, the data writing device 40 further includes a broadcast module 404 .
[0223] The processing module 403 is further configured to generate a second identifier for the index. The priority of the second identifier is higher than the priority of the first identifier for the index. The first identifier is the identifier of the index before the first node performs a split operation on the current page.
[0224] The broadcast module 404 is configured to broadcast the second identifier of the index.
[0225] Optionally, the processing module 403 is further configured to modify the split state of the index in the first node to stop splitting.
[0226] The processing module 403 is further configured to execute a release operation on the target lock.
[0227] Optionally, the receiving module 402 is further configured to receive a second lock resource acquisition response sent by the second node, where the second lock resource acquisition response is used to notify the target lock acquisition failure.
[0228] This application also provides a data writing device, such as Figure 10 As shown, the data writing device 50 includes: a receiving module 501 and a sending module 502.
[0229] Receiving module 501 is used to receive a lock resource release notification sent by the second node, which includes an identifier of a target lock. The lock resource release notification is used to notify the third node to perform a release operation on the target lock, which is the lock resource for which the first node requests a preset operation on the index.
[0230] The sending module 502 is configured to send a first lock resource release response to the second node when the split status of the index in the third node is stop splitting, where the first lock resource release response is used to notify that the target lock is successfully released.
[0231] Optionally, the data writing device 50 further includes a determination module 503 .
[0232] The determination module 503 is configured to determine whether the lock mode of the target lock is an exclusive lock when the split status of the index in the third node is splitting.
[0233] The sending module 502 is further configured to send a second lock resource release response to the second node when the lock mode of the target lock is an exclusive lock, where the second lock resource release response is used to notify the target lock of a release failure.
[0234] Optionally, the data writing device 50 further includes a broadcast module 504 .
[0235] The broadcast module 504 is configured to broadcast a target identifier when the split status of the index in the third node is stop splitting, where the target identifier is the identifier with the highest priority among the identifiers of the index.
[0236] As described above, the embodiment of the present application can divide the data writing device into functional modules according to the above method example. Among them, the above-mentioned integrated modules can be implemented in the form of hardware or in the form of software functional modules. In addition, it can be understood that the division of modules in the embodiment of the present application is schematic and is only a logical function division. In actual implementation, there can be other division methods. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module.
[0237] Regarding the data writing device in the above embodiment, the specific manner in which each module performs operations and the beneficial effects thereof have been described in detail in the aforementioned method embodiment and will not be repeated here.
[0238] Figure 11 This is a schematic diagram of the structure of another data writing device provided by this application. Figure 11 The data writing device 60 may include at least one processor 601 and a memory 603 for storing processor executable instructions. The processor 601 is configured to execute the instructions in the memory 603 to implement the data writing method in the above embodiment.
[0239] In addition, the data writing device 60 may further include a communication bus 602 and at least one communication interface 604 .
[0240] The processor 601 may be a central processing unit (CPU), a microprocessor unit, an ASIC, or one or more integrated circuits for controlling the execution of the program of the present application.
[0241] The communication bus 602 may include a pathway for transmitting information between the aforementioned components.
[0242] The communication interface 604 uses any transceiver or other device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area network (WLAN), etc.
[0243] The memory 603 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compressed optical disc, a laser disc, an optical disc, a digital versatile disc, a Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program codes in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may be independent and connected to the processing unit via a bus. The memory may also be integrated with the processing unit.
[0244] The memory 603 is used to store instructions for executing the solution of the present application, and the execution is controlled by the processor 601. The processor 601 is used to execute the instructions stored in the memory 603, thereby realizing the functions of the method of the present application.
[0245] In a specific implementation, as an embodiment, the processor 601 may include one or more CPUs, such as Figure 11 CPU0 and CPU1 in.
[0246] In a specific implementation, as an embodiment, the data writing device 60 may include multiple processors, such as Figure 11 6 and 607. Each of these processors may be a single-CPU processor or a multi-CPU processor. A processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0247] In a specific implementation, as an embodiment, the data writing device 60 may further include an output device 605 and an input device 606. The output device 605 communicates with the processor 601 and can display information in a variety of ways. For example, the output device 605 can be a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector. The input device 606 communicates with the processor 601 and can receive user input in a variety of ways. For example, the input device 606 can be a mouse, a keyboard, a touch screen device, or a sensor device.
[0248] Those skilled in the art will understand that Figure 11 The structure shown in the figure does not constitute a limitation to the data writing device 60, and the data writing device 60 may include more or fewer components than shown in the figure, or combine certain components, or adopt a different component arrangement.
[0249] In addition, the present application also provides a computer-readable storage medium, including instructions. When the instructions are executed by an electronic device, the electronic device executes the data writing method provided in the above embodiment.
[0250] In addition, the present application also provides a computer program product, including instructions, which, when executed by an electronic device, enable the electronic device to execute the data writing method provided in the above embodiment.
[0251] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of the present application and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered merely as exemplary, and the true scope and spirit of the present application are indicated by the claims.
Claims
1. A data writing method, characterized in that: Applied to the first node, the method includes: If the lock mode of the local lock of the first node does not satisfy the lock mode of the target lock, sending a lock resource acquisition request to the second node, where the lock resource acquisition request is used to request acquisition of the target lock, where the target lock is a lock resource for which the first node requests to perform a preset operation on the index; When the split status of the index in the third node is stop splitting, receiving a first lock resource acquisition response sent by the second node, where the first lock resource acquisition response is used to notify that the target lock is successfully acquired, and the third node is the previous node that performed the preset operation on the index; The splitting state of the index in the first node is modified to being split, and the index split is performed based on the target lock.
2. The data writing method according to claim 1, wherein: Before sending the lock resource acquisition request to the second node, the method further includes: When the lock mode of the local lock of the first node meets the lock mode of the target lock and the lock mode of the target lock is an exclusive lock, the split state of the index in the first node is modified to splitting, and the index splitting is performed based on the target lock.
3. The data writing method according to claim 1 or 2, characterized in that: The preset operation is a write operation, and performing index splitting based on the target lock includes: Performing a split operation on a current page of target data to obtain a target page, wherein the target data is data corresponding to the index; The write operation is performed on the target data in the current page and the target page based on the target lock.
4. The data writing method according to claim 3, wherein: The method further comprises: When there are no remaining pages in the current space of the target data, a memory request operation is performed to obtain the current page.
5. The data writing method according to claim 4, wherein: Before obtaining the current page, the method further includes: Performing a release operation on the target lock; After obtaining the current page, the method further includes: A locking operation is performed on the index based on the target lock.
6. The data writing method according to any one of claims 1 to 5, characterized in that: After performing index splitting based on the target lock, the method further includes: Generate a second identifier for the index, where the priority of the second identifier is higher than the priority of the first identifier for the index, where the first identifier is the identifier of the index before the first node performs a split operation on the current page; A second identifier of the index is broadcasted.
7. The data writing method according to any one of claims 1 to 6, characterized in that: After performing index splitting based on the target lock, the method further includes: Modify the split state of the index in the first node to stop splitting; A release operation is performed on the target lock.
8. The data writing method according to any one of claims 1 to 7, characterized in that: The method further comprises: A second lock resource acquisition response sent by the second node is received, where the second lock resource acquisition response is used to notify the target lock that acquisition has failed.
9. A data writing method, characterized in that: Applied to the third node, the method includes: receiving a lock resource release notification sent by the second node, the lock resource release notification including an identifier of a target lock, the lock resource release notification being used to notify the third node to perform a release operation on the target lock, the target lock being the lock resource for which the first node requested a preset operation on the index; When the split status of the index in the third node is stop splitting, a first lock resource release response is sent to the second node, where the first lock resource release response is used to notify that the target lock is successfully released.
10. The data writing method according to claim 9, wherein: The method further comprises: When the splitting state of the index in the third node is splitting, determining whether the lock mode of the target lock is an exclusive lock; When the lock mode of the target lock is an exclusive lock, a second lock resource release response is sent to the second node, where the second lock resource release response is used to notify the target lock of a release failure.
11. The data writing method according to claim 9 or 10, characterized in that: The method further comprises: When the split state of the index in the third node is stop splitting, a target identifier is broadcasted, where the target identifier is an identifier with the highest priority among the identifiers of the index.
12. A data writing device, characterized in that: Applied to a first node, the apparatus includes a sending module, a receiving module, and a processing module; The sending module is configured to send a lock resource acquisition request to the second node when the lock mode of the local lock of the first node does not satisfy the lock mode of the target lock, wherein the lock resource acquisition request is used to request to acquire the target lock, and the target lock is a lock resource for which the first node requests to perform a preset operation on the index; The receiving module is configured to receive, when the split status of the index in the third node is "stop splitting", a first lock resource acquisition response sent by the second node, the first lock resource acquisition response being used to notify that the target lock is successfully acquired, and the third node being the previous node that performed the preset operation on the index; The processing module is configured to modify the splitting state of the index in the first node to being split, and perform index splitting based on the target lock.
13. The data writing device according to claim 12, wherein: The processing module is also used to modify the split state of the index in the first node to splitting when the lock mode of the local lock of the first node meets the lock mode of the target lock and the lock mode of the target lock is an exclusive lock, and perform index splitting based on the target lock.
14. The data writing device according to claim 12 or 13, characterized in that: The preset operation is a write operation; The processing module is specifically configured to perform a split operation on a current page of target data to obtain a target page, where the target data is data corresponding to the index; The processing module is further specifically configured to perform the write operation on the target data in the current page and the target page based on the target lock.
15. The data writing device according to claim 14, wherein: The processing module is further configured to execute a memory request operation to obtain the current page when there are no remaining pages in the current space of the target data.
16. The data writing device according to claim 15, wherein: The processing module is further configured to perform a release operation on the target lock before acquiring the current page; The processing module is further configured to perform a locking operation on the index based on the target lock after acquiring the current page.
17. The data writing device according to any one of claims 12 to 16, characterized in that: The device also includes a broadcast module; The processing module is further configured to generate a second identifier for the index, where the priority of the second identifier is higher than the priority of the first identifier for the index, where the first identifier is the identifier of the index before the first node performs a split operation on the current page; The broadcast module is configured to broadcast the second identifier of the index.
18. The data writing device according to any one of claims 12 to 17, characterized in that: The processing module is further configured to modify the split state of the index in the first node to stop splitting; The processing module is further configured to perform a release operation on the target lock.
19. The data writing device according to any one of claims 12 to 18, characterized in that: The receiving module is further configured to receive a second lock resource acquisition response sent by the second node, where the second lock resource acquisition response is used to notify the target lock acquisition failure.
20. A data writing device, characterized in that: Applied to a third node, the device includes a receiving module and a sending module; The receiving module is configured to receive a lock resource release notification sent by the second node, the lock resource release notification including an identifier of a target lock, and the lock resource release notification is configured to notify the third node to perform a release operation on the target lock, where the target lock is a lock resource for which the first node requests a preset operation on the index; The sending module is configured to send a first lock resource release response to the second node when the split status of the index in the third node is stop splitting, where the first lock resource release response is used to notify the successful release of the target lock.
21. The data writing device according to claim 20, wherein: The apparatus further includes a determination module; The determining module is configured to determine whether the lock mode of the target lock is an exclusive lock when the splitting state of the index in the third node is splitting; The sending module is further configured to send a second lock resource release response to the second node when the lock mode of the target lock is an exclusive lock, where the second lock resource release response is used to notify the target lock of a release failure.
22. The data writing device according to claim 21 or 20, characterized in that: The device also includes a broadcast module; The broadcast module is configured to broadcast a target identifier when the split status of the index in the third node is stop splitting, where the target identifier is an identifier with the highest priority among the identifiers of the index.
23. An electronic device, characterized in that: The electronic device comprises: Memory; Communication interface; one or more processors; Wherein, one or more computer programs are stored in the memory, and the one or more computer programs include instructions. When the instructions are executed by the electronic device, the electronic device executes the data writing method as described in any one of claims 1-8 or the data writing method as described in any one of claims 9-11.
24. A computer-readable storage medium, characterized in that The method comprises computer instructions, which, when executed on an electronic device, enable the electronic device to execute the data writing method according to any one of claims 1 to 8 or the data writing method according to any one of claims 9 to 11.
25. A computer program product comprising instructions, characterized in that When the instruction is executed on an electronic device, the electronic device executes the data writing method according to any one of claims 1 to 8 or the data writing method according to any one of claims 9 to 11.