Data reading and writing method and device
By obtaining and modifying locking information in a distributed database, the problem that distributed lock solutions cannot be applied to devices that do not support the SCSI protocol is solved, achieving better versatility and data read/write efficiency, and ensuring data integrity and consistency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2026-03-27
AI Technical Summary
In existing technologies, distributed lock schemes for distributed databases cannot be applied to devices that do not support the SCSI protocol, resulting in poor versatility.
By obtaining the locking information of the address to be read/written, it is determined whether other nodes have locked it. If no other nodes have locked it, the locking information is modified to lock the address by the first node, ensuring the integrity and consistency of data read/write operations, without relying on the SCSI protocol.
The distributed lock achieves better versatility, is simple and efficient to use, consumes fewer resources, improves data read and write efficiency, and ensures data integrity and consistency.
Smart Images

Figure CN121743401A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data reading and writing, and in particular to a data reading and writing method and apparatus. Background Technology
[0002] In the field of distributed databases, locking is a technique used for concurrent access to distributed databases. Locking can ensure the integrity and consistency of data when multiple users or processes access the distributed database at the same time.
[0003] In related technologies, distributed locks used for distributed databases are implemented based on the Small Computer System Interface (SCSI) protocol. However, this approach cannot be applied to devices that do not support the SCSI protocol, resulting in poor versatility. Summary of the Invention
[0004] This application provides a data read / write method and apparatus that can improve the versatility of distributed lock schemes.
[0005] Firstly, this application provides a data read / write method. This data read / write method can be executed by nodes in a database system (e.g., a distributed database system), for example, by the first node.
[0006] The method includes the following steps: obtaining locking information for the address to be read / written, wherein the locking information indicates the locking status of multiple nodes with access permissions for the address to be read / written, that is, indicating whether each of the multiple nodes has locked the address to be read / written, and the multiple nodes with access permissions include the first node; if the locking information indicates that none of the multiple nodes with access permissions have locked the address to be read / written, that is, if the address to be read / written is not locked by any node, modify the locking information, and the modified locking information indicates that the first node has locked the address to be read / written; obtaining the locking information again; if the locking information indicates that none of the other nodes except the first node have locked the address to be read / written, that is, if the address to be read / written is locked only by the first node, perform data read / write operations on the address to be read / written.
[0007] The multiple nodes here refer to multiple database nodes in the database system, all of which have permission to access the address to be read and written. The first node is any one of these nodes. In other words, multiple nodes perform data read and write operations according to this method.
[0008] In this embodiment, by obtaining the locking information of the address to be read / written, it is determined whether the address is locked by other nodes. If it is not locked by other nodes, the locking information is modified to lock the address. After locking, the locking information is read again to prevent other nodes from locking the address simultaneously. If it is determined that no other node has locked the address simultaneously, data read / write operations are performed. This method implements data locking for distributed nodes without using the SCSI protocol. The locking scheme in this data read / write method is applicable to various nodes (including nodes that do not support the SCSI protocol), has better versatility, and the use of locks is simple and efficient, with low resource consumption, thus improving data read / write efficiency.
[0009] In this embodiment, the locking information is stored in a storage device. By storing the locking information in a storage device, normal access by each node can be guaranteed.
[0010] In one example of this application, the locking information includes multiple fields, each of which corresponds to a node with access rights. The first value of a field indicates that the corresponding node has locked the address to be read or written, and the second value of a field indicates that the corresponding node has not locked the address to be read or written.
[0011] In this implementation, multiple fields are designed to correspond to multiple nodes, and each field uses two different values to indicate whether locking is required. This approach is simple to implement and consumes few resources.
[0012] In other examples of this application, the locking information may also take other formats, such as charts, etc.
[0013] For example, modifying the locking information includes:
[0014] Based on the correspondence between multiple nodes and multiple fields in the locking information, determine the field corresponding to the first node;
[0015] Modify the field corresponding to the first node in the locking information from the second value to the first value, thereby indicating that the first node has locked the address to be read and written.
[0016] In this implementation, when locking data, you only need to find the corresponding field of the node and then modify the value. The use of locks is simple and efficient.
[0017] Optionally, the method further includes:
[0018] Before modifying the locking information, if the locking information indicates that any node with access rights has locked the address to be read / written, wait for a certain period of time before obtaining the locking information for the address to be read / written.
[0019] In this implementation, the locking information determines that other nodes have already locked the address to be read or written. Therefore, it is necessary to wait for other nodes to complete the read or write operation and for no other node to lock before the locking operation can be performed to ensure the integrity and consistency of the data.
[0020] Optionally, the method further includes:
[0021] After modifying the locking information, if the locking information indicates that at least one node other than the first node has locked the address to be read and written, modify the locking information again. The modified locking information indicates that the first node has not locked the address to be read and written.
[0022] After the waiting period, obtain the locking information for the address to be read / written.
[0023] In this implementation, locking information is used to determine if other nodes are locking the address to be read or written at the same time. Therefore, the locking operation can only be performed after the other nodes have completed their read and write operations and no other nodes are locking the address, thus ensuring the integrity and consistency of the data.
[0024] Optionally, the method further includes:
[0025] After the data read / write operation is completed, the locking information is modified. The modified locking information indicates that the first node has not locked the address to be read / written.
[0026] In this implementation, after completing the data read / write operation, the locking information is modified to unlock the address to be read / written, allowing other nodes to lock and read / write data.
[0027] Secondly, this application provides a data read / write device, which includes:
[0028] The acquisition unit is used to acquire the locking information of the address to be read and written. The locking information indicates the locking status of multiple nodes with access permissions for the address to be read and written. The multiple nodes with access permissions include the first node.
[0029] The locking unit is used to modify the locking information when the locking information indicates that none of the multiple nodes with access rights have locked the address to be read and written. The modified locking information instructs the first node to lock the address to be read and written.
[0030] The acquisition unit is also used to acquire the lock information again;
[0031] The read / write unit is used to perform data read / write operations on the address to be read / written when the locking information indicates that none of the other nodes except the first node have locked the address to be read / written.
[0032] For example, the locking information includes multiple fields, each of which corresponds to a node with access rights. The first value of a field indicates that the corresponding node has locked the address to be read or written, and the second value of a field indicates that the corresponding node has not locked the address to be read or written.
[0033] For example, the locking unit is used to determine the field corresponding to the first node based on the correspondence between multiple nodes and multiple fields in the locking information; and to modify the field corresponding to the first node in the locking information from a second value to a first value.
[0034] Optionally, the acquisition unit is also configured to acquire the lock information of the address to be read / written after waiting for a period of time, in the case where the lock information indicates that any node with access rights has locked the address to be read / written, before modifying the lock information.
[0035] Optionally, the locking unit is further configured to modify the locking information after modifying the locking information, in the case where the locking information indicates that at least one node other than the first node has locked the address to be read and written, and the modified locking information indicates that the first node has not locked the address to be read and written.
[0036] The acquisition unit is also used to acquire the locking information of the address to be read or written after waiting for a certain period of time.
[0037] Optionally, the locking unit is also used to modify the locking information after the data read / write operation is completed. The modified locking information indicates that the first node has not locked the address to be read / written.
[0038] For example, the locking information is stored in a storage device.
[0039] Thirdly, a computer device is provided. The computer device includes a processor and a memory. The memory is used to store software programs and modules. The processor implements the methods described in the first aspect or any possible implementation of the first aspect by running or executing the software programs and / or modules stored in the memory.
[0040] Optionally, the processor may be one or more, and the memory may be one or more.
[0041] Optionally, the memory may be integrated with the processor, or the memory may be separated from the processor.
[0042] In the specific implementation process, the memory can be a non-transitory memory, such as read-only memory (ROM), which can be integrated with the processor on the same chip or set on different chips. This application does not limit the type of memory or the way the memory and processor are set.
[0043] Fourthly, a computer program product is provided. The computer program product includes computer program code that, when executed by a device, causes the device to perform the methods described in the first aspect or any possible implementation thereof.
[0044] Fifthly, this application provides a computer-readable storage medium for storing program code executed by a processor, the program code including methods for implementing any of the possible embodiments of the first aspect described above.
[0045] In a sixth aspect, a chip is provided, including a processor for retrieving and executing instructions stored in a memory, such that a computer device on which the chip is mounted performs the method described in any of the possible embodiments of the first aspect.
[0046] In a seventh aspect, another chip is provided. The other chip includes an input interface, an output interface, a processor, and a memory. The input interface, the output interface, the processor, and the memory are connected via internal interconnection paths. The processor is used to execute code in the memory, and when the code is executed, the processor is used to perform the method in any of the possible embodiments of the first aspect described above. Attached Figure Description
[0047] Figure 1 This is a schematic diagram of the structure of a database system provided in an embodiment of this application;
[0048] Figure 2 This is a functional block diagram of a database system provided in an embodiment of this application;
[0049] Figure 3 This is a flowchart of a data read / write method provided in an embodiment of this application;
[0050] Figure 4 This is a flowchart of a data read / write method provided in an embodiment of this application;
[0051] Figure 5 This is a schematic diagram illustrating a change in locking information provided in an embodiment of this application;
[0052] Figure 6 This is another schematic diagram of the change in locking information provided in an embodiment of this application;
[0053] Figure 7 This is a block diagram of a data read / write device provided in an embodiment of this application;
[0054] Figure 8 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0056] To address the problems existing in related technologies, embodiments of this application provide a data reading and writing method and apparatus. To facilitate understanding of the technical solutions provided in these embodiments, some technical terms involved in this application are briefly explained first:
[0057] Locking: When a node needs to read or write a certain piece of data (i.e., an address), it requests the file system to set a lock on that data to prevent other nodes from reading or writing to that data at the same time.
[0058] Unlock: When a node completes a read or write operation on a certain piece of data (i.e., an address), it requests the file system to remove the lock set for that data, so that other nodes can read and write that data.
[0059] The solution provided in this application can be applied to scenarios involving data locking, such as distributed databases. Taking distributed databases as an example, the solution provided in this application is mainly applied to distributed databases with a shared everything architecture. In this architecture, multiple distributed nodes access the same data through shared storage. In order to enable multiple nodes to access the same data in the shared storage, a locking mechanism is required to prevent different nodes from accessing the same data simultaneously.
[0060] The following is combined with Figure 1 The scenarios to which the solutions provided in the embodiments of this application are applicable are illustrated by way of example. Figure 1 This is a schematic diagram of the structure of a database system provided in an embodiment of this application. For example... Figure 1 As shown, the database system includes multiple database nodes 10 and storage devices 20.
[0061] In one example, storage device 20 may be a shared disk, and accordingly, the data read / write method of this application is used to read and write disk data. In other examples, storage device 20 may also be other storage media.
[0062] like Figure 1 As shown, database node 10 includes a distributed storage service (DSS) instance and a database (DB) instance, with the DB instance including the DSS server.
[0063] The DSS server provides a file access interface for the database, and the DSS instance is the DSS metadata control module. The DSS server, DB instance, and DSS instance constitute the file system in database node 10, used to manage and access storage devices and implement read and write operations.
[0064] When the database system is a distributed database system, the aforementioned multiple database nodes 10 are distributed nodes, and the file system in the distributed nodes is a distributed file system.
[0065] The data read / write method provided in this application embodiment can be executed by a database node, such as by a DSS in the node.
[0066] Figure 2 This is a functional block diagram of a database system provided in an embodiment of this application. For example... Figure 2 As shown, the file system in database node 10 includes functions such as disk description, distributed locks, space management, file management, and communication management. Storage device 20 includes data partitions such as lock areas, metadata, and data areas.
[0067] This application embodiment uses the distributed lock function in the file system, combined with the data stored in the lock area of the storage device 20, to implement a distributed lock without the need for the SCSI protocol.
[0068] Figure 3 This is a flowchart illustrating a data read / write method provided in an embodiment of this application. This method can be executed by nodes in a database system (e.g., a distributed database system), for example, by a first node. Figure 3 As shown, the method includes the following steps.
[0069] 101: Obtain the locking information of the address to be read / written.
[0070] In the embodiments of this application, the locking information indicates the locking status of multiple nodes with access permissions for the address to be read and written, that is, it indicates whether each of the multiple nodes has locked the address to be read and written.
[0071] In this context, the multiple nodes with access permissions include the first node. These multiple nodes refer to multiple database nodes in the database system, all of which have permission to access the address to be read and written. The first node is any one of these multiple nodes. That is, multiple nodes perform data read and write operations according to this method.
[0072] 102: If the locking information indicates that multiple nodes with access rights have not locked the address to be read / written, modify the locking information so that the first node locks the address to be read / written.
[0073] That is, if the address to be read / written is not locked by any other node, then the address to be read / written is locked.
[0074] 103: Retrieve lock information again.
[0075] The purpose of obtaining the locking information again after locking is to re-determine whether other nodes have locked the node, thus avoiding the situation where other nodes lock the node at the same time as the first node.
[0076] 104: If the locking information indicates that no other node except the first node has locked the address to be read or written, perform data read / write operations on the address to be read or written.
[0077] In other words, data read and write operations are performed only when the address to be read or written is locked by the first node.
[0078] In this embodiment, by obtaining the locking information of the address to be read / written, it is determined whether the address is locked by other nodes. If it is not locked by other nodes, the locking information is modified to lock the address. After locking, the locking information is read again to prevent other nodes from locking the address simultaneously. If it is determined that no other node has locked the address simultaneously, data read / write operations are performed. This method implements data locking for distributed nodes without using the SCSI protocol. The locking scheme in this data read / write method is applicable to various nodes (including nodes that do not support the SCSI protocol), has better versatility, and the use of locks is simple and efficient, with low resource consumption, thus improving data read / write efficiency.
[0079] Figure 4 This is a flowchart illustrating a data read / write method provided in an embodiment of this application. This method can be executed by nodes in a database system (e.g., a distributed database system), for example, by a first node. Figure 4 As shown, the method includes the following steps.
[0080] 201: Get the locking information of the address to be read / written.
[0081] In this embodiment of the application, the locking information indicates the locking status of multiple nodes with access permissions for the address to be read and written, and the multiple nodes with access permissions include the first node.
[0082] The multiple nodes here refer to multiple database nodes in the database system, all of which have permission to access the address to be read and written. The first node is any one of these nodes. In other words, multiple nodes perform data read and write operations according to this method.
[0083] In this embodiment, the locking information is stored in a storage device. By storing the locking information in a storage device, normal access by each node can be guaranteed.
[0084] like Figure 2 As shown, the locking information is stored in the lock area of the storage device. This lock area can be the header of the storage device, for example, a header region can be partitioned as a shared lock area in a shared disk. In a distributed file system, the distributed lock interacts with the lock area to enable multiple nodes to correctly access shared disk data. The lock area can also be other areas, and this embodiment does not limit this.
[0085] In this embodiment, the data area in the storage device stores data resources. Addresses are divided according to the storage space of the data resources or data area to obtain multiple data area addresses. The address to be read / written is one of these multiple data area addresses. This embodiment does not concern itself with the method or granularity of configuring these data area addresses.
[0086] The lock area can be accessed by any of the multiple nodes. The lock area stores the locking information (also known as the lock structure) of the addresses of the multiple data areas mentioned above in the storage device.
[0087] The database node is configured with a mapping relationship between multiple data area addresses and the corresponding locking information addresses (lock area addresses). Accordingly, step 201 includes:
[0088] Determine the address of the data area to be accessed, i.e., the address to be read or written;
[0089] Based on the correspondence between multiple data area addresses and the addresses of the corresponding locking information, the address of the locking information corresponding to the address to be read / written is determined;
[0090] Locking information is read from the storage device based on the address of the locking information.
[0091] In this implementation, a corresponding lock structure is designed for each data area address using the above method, so that each node can easily obtain the lock structure of the data area address to be accessed, realize data locking, and thus complete data reading and writing.
[0092] In one example of the embodiments of this application, the locking information includes multiple fields, which correspond one-to-one with multiple nodes that have access permissions. The first value of the field indicates that the corresponding node has locked the address to be read and written, and the second value of the field indicates that the corresponding node has not locked the address to be read and written.
[0093] In this implementation, multiple fields are designed to correspond to multiple nodes, and each field uses two different values to indicate whether locking is required. This approach is simple to implement and consumes few resources.
[0094] The above fields form an array.
[0095] In one example, each element of the array is indicated by 0 or 1 to indicate whether it is locked, for example, 0 means unlocked and 1 means locked.
[0096] In other examples, each element in the array can also use other numerical values, or even other characters, to represent locked and unlocked.
[0097] In other examples of embodiments of this application, the locking information may also take other formats, such as charts, etc.
[0098] The database nodes are also configured with a correspondence between multiple nodes and multiple fields in the locking information, so that each node knows which field to modify when locking.
[0099] After the first node reads the locking information, it can determine the locking status of the address to be read and written by each node based on the value of each field in the locking information.
[0100] If the locking information indicates that any node with access rights has locked the address to be read / written, proceed to step 202; if the locking information indicates that none of the nodes with access rights have locked the address to be read / written, proceed to step 203.
[0101] Taking the locking information as an array as an example, when all elements of the array are 0, step 203 is executed; when any element of the array is 1, since the first node has not yet performed a locking operation, the existence of an element with a value of 1 indicates that other nodes have locked, so step 202 is executed.
[0102] 202: After the waiting period, obtain the locking information of the address to be read / written.
[0103] In this step, the locking information determines that other nodes have already locked the address to be read and written. Therefore, it is necessary to wait for a certain period of time to allow other locking nodes to complete the read and write operations and unlock the address. Then, the first node re-executes step 201 to ensure that no other node has locked the address before the locking operation can be performed, thus ensuring the integrity and consistency of the data.
[0104] In one example of the embodiments of this application, the periodic time can be a fixed time length.
[0105] In another example of the embodiments of this application, the periodic time can also be a random time length, for example, random within a set time range.
[0106] For example, the period time can be set according to the needs of the scenario. For instance, in a distributed database, the period time can be on the order of milliseconds.
[0107] For example, step 202 may include: determining the period time; setting a timer; and when the timer reaches the period time, reacquiring the locking information of the address to be read / written.
[0108] 203: Modify locking information. The modified locking information instructs the first node to lock the address to be read / written.
[0109] For example, this step includes: determining the field corresponding to the first node based on the correspondence between multiple nodes and multiple fields in the locking information; modifying the field corresponding to the first node in the locking information from a second value to a first value, thereby indicating that the first node has locked the address to be read and written.
[0110] In this implementation, when locking data, you only need to find the corresponding field of the node and then modify the value. The use of locks is simple and efficient.
[0111] 204: Retrieve lock information again.
[0112] The method for obtaining the locking information is the same as in step 201, and will not be repeated here.
[0113] After the first node reads the locking information, it can determine the locking status of the address to be read and written by each node based on the value of each field in the locking information.
[0114] If the locking information indicates that at least one node other than the first node has locked the address to be read / written, proceed to step 205; if the locking information indicates that none of the other nodes other than the first node have locked the address to be read / written, proceed to step 206.
[0115] The following is through Figure 5 and Figure 6 The two cases are illustrated by example.
[0116] Figure 5 This is a schematic diagram illustrating a change in locking information provided in an embodiment of this application. For example... Figure 5 As shown, the locking information includes three fields, corresponding to node 0, node 1, and node 2 respectively. Taking the operation process of node 0 as an example:
[0117] After node 0 reads the lock information, it determines that the lock information is all 0s, and it can lock at this time; node 0 writes 1 to the corresponding node to lock; after locking is completed, node 0 reads the lock information again and determines that except for its own corresponding field which is 1, all other fields are 0, indicating that other nodes are not currently locked, and then proceeds to step 206.
[0118] Figure 6 This is another schematic diagram illustrating changes in locking information provided in an embodiment of this application. For example... Figure 6 As shown, the locking information includes three fields, corresponding to node 0, node 1, and node 2 respectively. Taking the operation process of node 0 as an example:
[0119] After node 0 reads the lock area information, it determines that the lock area information is all 0s, and it can lock at this time. Node 0 writes 1 to the corresponding node to lock. After locking is completed, node 0 reads the lock area information again and determines that in addition to its own corresponding field being 1, the corresponding field of node 1 is also 1, indicating that node 1 has also locked. At this time, step 205 is executed to write its own corresponding field back to 0.
[0120] 205: Modify locking information. The modified locking information indicates that the first node has not locked the address to be read or written; after waiting for the cycle time, obtain the locking information of the address to be read or written.
[0121] For example, this step includes: determining the field corresponding to the first node based on the correspondence between multiple nodes and multiple fields in the locking information; and modifying the field corresponding to the first node in the locking information from a first value to a second value.
[0122] In this step, the locking information determines that other nodes are locking the address to be read and written at the same time. Therefore, it is necessary to unlock and wait for the period of time to allow other nodes to complete the read and write operations. Then, the first node re-executes step 201 to determine that the locking operation can only be performed if no other node is locking, so as to ensure the integrity and consistency of the data.
[0123] Since both locking and unlocking require operation time, simultaneous locking and unlocking can occur, causing both nodes to fail. Tables 1 and 2 below illustrate the success and failure scenarios of nodes A and B under different operation sequences:
[0124] Table 1
[0125]
[0126] Table 2
[0127]
[0128]
[0129] In the example shown in Table 1, node A shows only one timing rwr, where r represents node A read (corresponding to steps 201 and 204), and w represents node A write (corresponding to step 203); node B shows 20 timing RWR, where R represents node B read (corresponding to steps 201 and 204), and W represents node B write (corresponding to step 203).
[0130] As can be seen, for a node, the start time of the first read is not fixed, that is, the start time of step 201 is not fixed, and the time interval between read and write is not fixed, that is, the time interval between steps 201 and 203, and between steps 203 and 204 is not fixed. These times and time intervals are related to the node's capabilities, resource usage, etc.
[0131] Table 2 shows the final locking results under the 20 timing sequences for node B in Table 1. It can be seen that a successful lock occurs for at most one node, while "no" indicates that two nodes were successfully locked. Among the reasons for failure, a single check failure indicates that after executing step 201, another node was found to be locked; a second check failure indicates that after executing step 204, another node was found to be locked. The full timing sequence represents the sequence of read and write steps according to the order in Table 1. However, due to check failures, some nodes may not have actually completed all three steps, thus obtaining the actual timing sequence.
[0132] Taking the first example of node B as an example, since node B completes the RWR step first, when node A completes the first r operation, the check finds that B has already acquired the lock, so it will not execute the subsequent w and r operations. Therefore, the actual timing is RWRr.
[0133] In the example above, when node verification fails and execution stops, it will wait for a certain period of time before retrying.
[0134] Tables 1 and 2 above only show the case of two nodes. When multiple nodes need to access a certain data area address, each node executes the scheme of this application embodiment. In the end, only one node can successfully lock, or all nodes fail to lock.
[0135] 206: Perform data read / write operations on the address to be read / written.
[0136] For example, the first node writes data to the address to be read or written, or the first node reads data from the address to be read or written.
[0137] In this embodiment of the application, since the method can be executed by the DSS in the database node, and usually the DB in the database node calls the DSS to execute it, the DSS can send a read / write success message to the DB in the database node when the read / write operation is completed.
[0138] 207: After the data read / write operation is completed, modify the locking information. The modified locking information indicates that the first node has not locked the address to be read / written.
[0139] For example, this step includes: determining the field corresponding to the first node based on the correspondence between multiple nodes and multiple fields in the locking information; and modifying the field corresponding to the first node in the locking information from a first value to a second value.
[0140] In this step, after the data read and write operations are completed, the locking information is modified to unlock the address to be read and written, so that other nodes can lock and read and write data.
[0141] The data read / write method provided in the embodiments of this application includes a shared lock area mechanism and a read-write-read locking algorithm. The shared lock area mechanism refers to using a software algorithm to divide a region on a shared disk as a lock area. Shared resources in the data area have corresponding locks within the lock area, and each node has an exclusive slot (field) in the lock structure, representing whether the node is locked. The read-write-read locking algorithm involves first reading the lock to determine if it is idle, then modifying the corresponding slot within the lock for the current node, and finally reading the lock again to ensure that no other nodes are concurrently acquiring the lock.
[0142] Through the aforementioned mechanisms and algorithms, the distributed lock implementation for controlling resource access no longer requires hardware support for the SCSI protocol and can be implemented on any shared disk device, better meeting the needs of cloud scenarios. Furthermore, the read-write-read locking algorithm ensures locking correctness and is simple and efficient to use.
[0143] Figure 7 This is a block diagram of a data read / write device provided in an embodiment of this application. This data read / write device can be implemented through software, hardware, or a combination of both to become all or part of a node in a database system (e.g., a distributed database system). The data read / write device may include: an acquisition unit 301, a locking unit 302, and a read / write unit 303.
[0144] The acquisition unit 301 is used to acquire the locking information of the address to be read and written. The locking information indicates the locking status of multiple nodes with access permissions for the address to be read and written. The multiple nodes with access permissions include the first node.
[0145] The locking unit 302 is used to modify the locking information when the locking information indicates that none of the multiple nodes with access rights have locked the address to be read and written. The modified locking information instructs the first node to lock the address to be read and written.
[0146] The acquisition unit 301 is also used to acquire the locking information again;
[0147] The read / write unit 303 is used to perform data read / write operations on the address to be read / written when the locking information indicates that none of the other nodes except the first node have locked the address to be read / written.
[0148] For example, the locking information includes multiple fields, each of which corresponds to a node with access rights. The first value of a field indicates that the corresponding node has locked the address to be read or written, and the second value of a field indicates that the corresponding node has not locked the address to be read or written.
[0149] For example, the locking unit 302 is used to determine the field corresponding to the first node based on the correspondence between multiple nodes and multiple fields in the locking information; and to modify the field corresponding to the first node in the locking information from a second value to a first value.
[0150] Optionally, the acquisition unit 301 is also used to acquire the lock information of the address to be read and written after waiting for a period of time before modifying the lock information, in the case where the lock information indicates that any node with access rights has locked the address to be read and written.
[0151] Optionally, the locking unit 302 is further configured to modify the locking information after modifying the locking information, in the case where the locking information indicates that at least one node other than the first node has locked the address to be read and written, and the modified locking information indicates that the first node has not locked the address to be read and written.
[0152] The acquisition unit 301 is also used to acquire the locking information of the address to be read or written after waiting for a period of time.
[0153] Optionally, the locking unit 302 is also used to modify the locking information after the data read / write operation is completed. The modified locking information indicates that the first node has not locked the address to be read / written.
[0154] For example, the locking information is stored in a storage device.
[0155] It should be noted that the data read / write device provided in the above embodiments is only illustrated by the division of the above functional units when performing data read / write. In practical applications, the above functions can be assigned to different functional units as needed, that is, the internal structure of the device can be divided into different functional units to complete all or part of the functions described above. In addition, the data read / write device and the data read / write method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0156] Figure 8 A schematic diagram of the structure of a computer device 150 provided in an embodiment of this application is shown. This computer device can be a node in the aforementioned database system (e.g., a distributed database system). Figure 8 The computer device 150 shown is used to perform the above. Figure 3 or Figure 4 The data read / write method shown involves the operations described. This computer device 150 can be implemented using a general bus architecture.
[0157] like Figure 8 As shown, the computer device 150 includes at least one processor 151, a memory 153, and at least one communication interface 154.
[0158] Processor 151 may be, for example, a general-purpose central processing unit (CPU), a digital signal processor (DSP), a network processor (NP), a data processing unit (DPU), a microprocessor, or one or more integrated circuits for implementing the embodiments of this application. For example, processor 151 may include an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. A PLD may be, for example, a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof. It can implement or execute the various logic blocks, modules, and circuits described in connection with the embodiments of this application. A processor may also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0159] Optionally, the computer device 150 also includes a bus. The bus is used to transfer information between the various components of the computer device 150. The bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 8 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0160] Memory 153 may be, for example, read-only memory (ROM) or other types of static storage devices capable of storing static information and instructions; random access memory (RAM) or other types of dynamic storage devices capable of storing information and instructions; electrically erasable programmable read-only memory (EEPROM); compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.); magnetic disk storage media or other magnetic storage devices; or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Memory 153 may exist independently and be connected to processor 151 via a bus. Memory 153 may also be integrated with processor 151.
[0161] Communication interface 154 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), or Wireless Local Area Network (WLAN). Communication interface 154 may include wired and wireless communication interfaces. Specifically, communication interface 154 may be an Ethernet interface, Fast Ethernet (FE) interface, Gigabit Ethernet (GE) interface, Asynchronous Transfer Mode (ATM) interface, WLAN interface, cellular network communication interface, or a combination thereof. The Ethernet interface may be an optical interface, an electrical interface, or a combination thereof. In this embodiment, communication interface 154 can be used by computer device 150 to communicate with other devices.
[0162] In a specific implementation, as one example, processor 151 may include one or more CPUs, such as Figure 8 The CPU0 and CPU1 shown are examples of processors. Each of these processors can be a single-core processor or a multi-core processor. A processor here can refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).
[0163] In a specific implementation, as one example, the computer device 150 may include multiple processors, such as... Figure 8 The processors 151 and 155 shown are illustrated. Each of these processors can be a single-core processor or a multi-core processor. Here, "processor" can refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).
[0164] In a specific implementation, as one embodiment, the computer device 150 may further include an output device and an input device. The output device communicates with the processor 151 and can display information in various ways. For example, the output device may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device communicates with the processor 151 and can receive user input in various ways. For example, the input device may be a mouse, a keyboard, a touchscreen device, or a sensing device, etc.
[0165] In some embodiments, memory 153 is used to store program code 1510 for executing the solution of this application, and processor 151 can execute the program code 1510 stored in memory 153. That is, computer device 150 can execute program code 1510 in memory 153 through processor 151 to implement the data read and write method provided in the method embodiment. Program code 1510 may include one or more software modules. Optionally, processor 151 itself may also store program code or instructions for executing the solution of this application.
[0166] In a specific embodiment, the computer device 150 of this application embodiment may correspond to the controller in the above-described method embodiments. The processor 151 in the computer device 150 reads instructions from the memory 153, causing... Figure 8 The computer device 150 shown is capable of performing all or part of the operations performed by the controller.
[0167] Specifically, the processor 151 is used to acquire locking information of the address to be read / written, the locking information indicating the locking status of multiple nodes with access permissions for the address to be read / written, the multiple nodes with access permissions including a first node; if the locking information indicates that none of the multiple nodes with access permissions have locked the address to be read / written, the processor modifies the locking information, the modified locking information indicating that the first node has locked the address to be read / written; the processor acquires the locking information again; if the locking information indicates that none of the other nodes besides the first node have locked the address to be read / written, the processor performs data read / write operations on the address to be read / written.
[0168] Other alternative implementation methods will not be described in detail here for the sake of brevity.
[0169] in, Figure 3 or Figure 4 Each step of the data read / write method shown is completed by the integrated logic circuitry of the processor in the computer device 150 or by instructions in the form of software. The steps of the method disclosed in the embodiments of this application can be directly implemented by the hardware processor, or by a combination of hardware and software modules in the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. Since this storage medium is located in memory, the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method; to avoid repetition, these will not be described in detail here.
[0170] This application also provides a chip, including: an input interface, an output interface, a processor, and a memory. The input interface, output interface, processor, and memory are connected via internal interconnection paths. The processor is used to execute code in the memory, and when the code is executed, the processor is used to perform any of the data read / write methods described above.
[0171] It should be understood that the aforementioned processor can be a CPU, or it can be other general-purpose processors, DSPs, ASICs, FPGAs, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. General-purpose processors can be microprocessors or any conventional processor. It is worth noting that the processor can be a processor supporting the ARM architecture.
[0172] Further, in an optional embodiment, the processor and the memory may be one or more. Optionally, the memory may be integrated with the processor, or the memory may be separately configured from the processor. The memory may include read-only memory and random access memory, and provide instructions and data to the processor. The memory may also include non-volatile random access memory. For example, the memory may also store reference blocks and target blocks.
[0173] The memory can be volatile or non-volatile, or may include both. Non-volatile memory can be ROM, PROM, EPROM, EEPROM, or flash memory. Volatile memory can be RAM, used as an external cache. Many forms of RAM are available by way of example, but not limitation. Examples include SRAM, DRAM, SDRAM, DDR SDRAM, ESDRAM, SLDRAM, and DR RAM.
[0174] In this embodiment of the application, a computer-readable storage medium is also provided, which stores computer instructions. When the computer instructions stored in the computer-readable storage medium are executed by a computer device, the computer device performs the data read / write method provided above.
[0175] In this embodiment of the application, a computer program product containing instructions is also provided, which, when run on a computer device, causes the computer device to execute the data read / write method provided above.
[0176] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive).
[0177] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0178] The above description is merely an optional embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0179] Unless otherwise defined, the technical or scientific terms used herein shall have the ordinary meaning as understood by one of ordinary skill in the art to which this application pertains. The terms “first,” “second,” “third,” and similar terms used in this patent application specification and claims do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an” or “a” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The terms “comprising” or “including” and similar terms mean that the elements or objects preceding “comprising” or “including” encompass the elements or objects listed following “comprising” or “including” and their equivalents, and do not exclude other elements or objects.
[0180] The above is merely one embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A data read / write method, characterized in that, The data read / write method includes: Obtain the locking information of the address to be read and written, wherein the locking information indicates the locking status of multiple nodes with access permissions for the address to be read and written, and the multiple nodes with access permissions include the first node; If the locking information indicates that none of the multiple nodes with access permissions have locked the address to be read and written, the locking information is modified so that the first node locks the address to be read and written. Obtain the locking information again; If the locking information indicates that none of the nodes other than the first node have locked the address to be read / written, then data read / write operations are performed on the address to be read / written.
2. The method according to claim 1, characterized in that, The locking information includes multiple fields, each of which corresponds one-to-one with a node having access permissions. A first value in a field indicates that the corresponding node has locked the address to be read / written, while a second value in a field indicates that the corresponding node has not locked the address to be read / written.
3. The method according to claim 2, characterized in that, Modifying the locking information includes: Based on the correspondence between the multiple nodes and the multiple fields in the locking information, determine the field corresponding to the first node; Modify the field in the locking information corresponding to the first node from the second value to the first value.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: Before modifying the locking information, if the locking information indicates that any node with access rights locks the address to be read / written, the locking information of the address to be read / written is obtained after a waiting period.
5. The method according to any one of claims 1 to 3, characterized in that, The method further includes: After modifying the locking information, if the locking information indicates that at least one node other than the first node has locked the address to be read and written, the locking information is modified so that the modified locking information indicates that the first node has not locked the address to be read and written. After waiting for the specified period, obtain the locking information for the address to be read / written.
6. The method according to any one of claims 1 to 3, characterized in that, The method further includes: After the data read / write operation is completed, the locking information is modified. The modified locking information indicates that the first node has not locked the address to be read / written.
7. The method according to any one of claims 1 to 3, characterized in that, The locking information is stored in a storage device.
8. A data read / write device, characterized in that, The device includes: The acquisition unit is used to acquire locking information of the address to be read and written, wherein the locking information indicates the locking status of multiple nodes with access permissions for the address to be read and written, and the multiple nodes with access permissions include the first node; A locking unit is configured to modify the locking information when the locking information indicates that none of the multiple nodes with access rights have locked the address to be read and written. The modified locking information indicates that the first node locks the address to be read and written. The acquisition unit is also used to acquire the locking information again; The read / write unit is used to perform data read / write operations on the address to be read / written when the locking information indicates that none of the other nodes besides the first node have locked the address to be read / written.
9. A computer device, characterized in that, The device includes a memory and one or more processors, the memory being used to store a computer program; the one or more processors being used to execute the computer program in the memory, causing the computer device to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store program code executed by a processor, the program code including instructions for implementing the method as described in any one of claims 1 to 7.