WO2023124422A1 - 一种数据读写的控制方法及电子设备 - Google Patents

一种数据读写的控制方法及电子设备 Download PDF

Info

Publication number
WO2023124422A1
WO2023124422A1 PCT/CN2022/125972 CN2022125972W WO2023124422A1 WO 2023124422 A1 WO2023124422 A1 WO 2023124422A1 CN 2022125972 W CN2022125972 W CN 2022125972W WO 2023124422 A1 WO2023124422 A1 WO 2023124422A1
Authority
WO
WIPO (PCT)
Prior art keywords
write
read
flag
bit value
target data
Prior art date
Application number
PCT/CN2022/125972
Other languages
English (en)
French (fr)
Inventor
王剑
Original Assignee
深圳市兆珑科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市兆珑科技有限公司 filed Critical 深圳市兆珑科技有限公司
Publication of WO2023124422A1 publication Critical patent/WO2023124422A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline or look ahead

Definitions

  • the application belongs to the technical field of data processing, and in particular relates to a data reading and writing control method and electronic equipment.
  • a read-write lock in order to ensure the accuracy of editing data and avoid writing conflicts on the same data, a read-write lock can be configured so that there is one and only one write operation for the same data, and when writing Block other read operations on the data during the input operation.
  • the data volume of a certain data is large, it will take a long time to complete the addressing action on the editing element when performing a write operation, and blocking the read operation during the addressing process will greatly reduce the read rate of the data.
  • Write efficiency concurrency efficiency is low.
  • the embodiment of the present application provides a data reading and writing control method and electronic equipment to solve the existing data reading and writing control technology. If the data volume of a certain data is large, it needs It takes a long time to complete the addressing action of the editing element, and blocking the read operation during the addressing process greatly reduces the efficiency of reading and writing data, and the problem of low concurrency efficiency.
  • the first aspect of the embodiments of the present application provides a method for controlling data reading and writing, including:
  • the read-write parameters include a pre-write flag and a write flag
  • pre-writing identification bit is the first bit value
  • feed back the pre-writing approval instruction to the first process and set the pre-writing identification bit to the second bit value, so that the first process based on the application
  • the pre-write lock performs a pre-write operation; when the pre-write flag is at the second bit value, block and respond to pre-write lock application requests and write lock application requests initiated by other processes except the first process, Respond to the other process to initiate a read lock application request;
  • the write lock application request In response to the write lock application request for the target data initiated by the first process, perform a data editing operation on the target data; the write lock application request is completed after the first process executes the pre-write operation initiated after.
  • performing a data editing operation on the target data in response to the write lock application request for the target data initiated by the first process includes:
  • the read and write parameters include a read flag
  • the read flag is the third bit value
  • feed back the write approval instruction to the first process and set the write flag to the second bit value, so that the first process is based on the application
  • the write lock executes data editing operations; when the write flag is at the second bit value, the block responds to other processes initiating a pre-write lock application request, a write lock application request, and a read lock application request.
  • the method further includes:
  • the read flag is a bit value other than the third bit value, then determine the number of processes currently performing a read operation based on the read flag;
  • the first possible implementation manner of the first aspect also includes:
  • the read and write parameters In response to the read lock application request for the target data initiated by the second process, determine the read and write parameters of the target data; the read and write parameters also include a read flag;
  • write flag is the first bit value, feed back a read consent instruction to the second process, and increase the read flag, so that the second process performs a read operation based on the applied read lock .
  • the first possible implementation manner of the first aspect also includes:
  • the read and write parameters of the target data In response to the write lock application request for the target data initiated by the third process, determine the read and write parameters of the target data; the read and write parameters also include a read flag;
  • pre-write flag and the write flag are the first bit value, and the read flag is the third bit value, feed back the write approval command to the third process, and set the write flag to The second bit value is used to enable the third process to perform a data editing operation on the target data.
  • the method before responding to the write-ahead lock application request for the target data initiated by the first process, the method further includes:
  • the target data is a B+ tree index
  • the data editing operation is a deletion operation on a target element in the target data
  • the pre-writing identification bit is the first bit value, feeding back the pre-writing approval instruction to the first process, and setting the pre-writing identification bit as the second bit value, it also includes:
  • the pre-write lock applied for is released through the first process, and the pre-write flag is configured as the first one bit value
  • the write lock application request is initiated through the first process.
  • the priority of the write-ahead lock application request is higher than that of the write lock application request; the priority of the write lock application request is higher than that of the read lock application request class.
  • the second aspect of the embodiment of the present application provides a control device for reading and writing data, including:
  • the pre-write lock application unit is configured to determine the read-write parameters of the target data in response to the pre-write lock application request for the target data initiated by the first process; the read-write parameters include a pre-write flag and a write flag;
  • a pre-write trigger unit configured to feed back a pre-write approval instruction to the first process if the pre-write flag is a first bit value, and set the pre-write flag to a second bit value, so that The first process performs a pre-write operation based on the applied pre-write lock; when the pre-write flag is at the second bit value, blocking pre-write lock application requests initiated by other processes except the first process And write lock application request;
  • a write lock application unit configured to perform a data editing operation on the target data in response to a write lock application request for the target data initiated by the first process; the write lock application request is performed in the first process Initiated after the pre-write operation is completed.
  • the third aspect of the embodiment of the present application also provides a data read and write control device, which is used to allocate pre-write locks, write locks, and read locks according to read and write parameters, wherein the read and write parameters include: pre-write flags, write Identification bit and read identification bit;
  • the pre-write flag is the first bit value, it is allowed to respond to the pre-write application request initiated by the thread, so as to distribute the pre-write lock to the process that initiated the pre-write application request, and after assigning the pre-write lock to any process, Setting the pre-written identification bit as the second bit value;
  • the pre-write identification bit is the second bit value
  • the pre-write application request and the write application request initiated by the response thread are blocked, and the read application request inspired by the response thread is allowed.
  • the device for controlling data reading and writing is also used for:
  • the write flag and the pre-write lock are both the first bit value, it is allowed to respond to the write application request initiated by the thread, and when the read flag bit is the third bit value, it is allocated to the process that initiated the write application request write lock, and after assigning a write lock to any process, the write flag is set to the second value;
  • the pre-write application request, write application request and read application request initiated by the response thread are blocked.
  • the device for controlling data reading and writing is also used for:
  • the read identification bit is the third bit value, it is allowed to respond to the write application request initiated by the thread;
  • the write identification bit When the write identification bit is the first bit value, it is allowed to respond to the read application request initiated by the process, and allocate a read lock to the process that initiated the read application request, and configure the read identification bit according to the number of allocated read locks.
  • a third aspect of the embodiments of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and operable on the processor, when the processor executes the computer program
  • the various steps of the first aspect are realized.
  • a fourth aspect of the embodiments of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, each step of the first aspect is implemented.
  • a corresponding prewrite flag is added, and when the thread needs to perform a write operation that is addressed first, a prewrite lock application request can be initiated , when it is detected that the pre-write flag is at the first value, the pre-write approval command is fed back to the thread, that is, the pre-write lock is applied to the thread, and the pre-write operation can be performed; during the pre-write operation, the thread can Complete the addressing task and allow other processes to read the target data. After the addressing is completed, the process can initiate a write lock application request, and based on the execution of subsequent data editing operations, that is, write operations on the target data, to achieve Concurrent operations on the same target data.
  • this application can complete the addressing operation through the pre-write lock if the pre-write phase is used before the data is written, and other reads are allowed during the pre-write phase Operation, so that while avoiding conflicts between write operations, it can also reduce the exclusive time for data in the addressing process, and greatly improve the shared reading capability of data.
  • FIG. 1 is an implementation flowchart of a data reading and writing control method provided in the first embodiment of the present application
  • Fig. 2 is a schematic structural diagram of a B+ number index provided by an embodiment of the present application.
  • FIG. 3 is a specific implementation flow chart of a data reading and writing control method S103 provided in the second embodiment of the present application;
  • FIG. 4 is a schematic diagram of the timing sequence of multi-thread concurrency provided by an embodiment of the present application.
  • Fig. 5 is a specific implementation flowchart of a data reading and writing control method provided by the third embodiment of the present application.
  • FIG. 6 is a specific implementation flowchart of a control method for reading and writing data provided in the fourth embodiment of the present application.
  • Fig. 7 is a specific implementation flow chart of a data reading and writing control method provided by the fifth embodiment of the present application.
  • Fig. 8 is a specific implementation flowchart of a control method for reading and writing data provided in the sixth embodiment of the present application.
  • Fig. 9 is a structural block diagram of a control device for reading and writing data provided by an embodiment of the present application.
  • Fig. 10 is a schematic diagram of an electronic device provided by an embodiment of the present application.
  • a corresponding prewrite flag is added, and when the thread needs to perform a write operation that is addressed first, a prewrite lock application request can be initiated , when it is detected that the pre-write flag is at the first value, the pre-write approval command is fed back to the thread, that is, the pre-write lock is applied to the thread, and the pre-write operation can be performed; during the pre-write operation, the thread can Complete the addressing task and allow other processes to read the target data.
  • the process can initiate a write lock application request, and based on the execution of subsequent data editing operations, that is, write operations on the target data, to achieve
  • the concurrent operation of the same target data solves the control technology of data reading and writing. If the data volume of a certain data is large, it will take a long time to complete the addressing action of the editing element when performing the writing operation. Blocking the read operation during the process greatly reduces the efficiency of reading and writing data, and the problem of low concurrency efficiency.
  • the method for identifying abnormal requests provided by the embodiments of the present application can be applied to smart phones, servers, tablet computers, notebook computers, ultra-mobile personal computers (ultra-mobile personal computers) computer, UMPC), netbooks, servers and other electronic devices.
  • the embodiment of the present application does not impose any limitation on the specific type of the electronic device.
  • the electronic device is specifically a cloud server, and the cloud server stores at least one shared data.
  • the above-mentioned cloud server may include cloud documents, cloud computing, cloud applications, and cloud memory, etc. that provide cloud services. server.
  • the server can receive operations on the target data initiated by each terminal (if the cloud service is a cloud document, the above target data is specifically an electronic document; if the cloud service is cloud content, the above target data can be a specific memory address index table), the server can configure corresponding processes for operations initiated by different terminals, so as to achieve the purpose of sharing target data.
  • FIG. 1 shows an implementation flow chart of the data reading and writing control method provided in the first embodiment of the present application, which is described in detail as follows:
  • the user when the user needs to edit the target data, such as modifying, adding or deleting a certain element in the target data, the user can initiate a pre-write lock application request to the electronic device through the corresponding terminal .
  • the electronic device can configure a process for different terminals, and the terminal can perform operations such as reading and writing target data through the allocated process.
  • the electronic device specifically receives the terminal through the allocated process. Therefore, when the terminal needs to perform a pre-writing operation on the target data, it can initiate a pre-writing application request to the electronic device through the corresponding first process.
  • each process may determine whether the process needs to perform the pre-write operation according to whether the address of the element to be written has been determined. If a process has determined the address of the element to be written, the process can directly perform the write operation without pre-writing. In this case, the first process can initiate a write lock application request to directly execute Data editing operation; on the contrary, if a certain process has not determined the address of the element to be written, that is, it needs to be addressed, then the process needs to perform the pre-write operation before performing the write operation. Based on this, the first process needs Initiate a pre-write lock application request to determine the address of the element to be written in the pre-write phase, and apply for a write lock after determining the address of the element.
  • the addressing process is not completed instantaneously.
  • the shared content database is configured with an index table based on a B+ tree.
  • Each process can The addressing of memory resources can only be completed by determining the corresponding nodes and positions of each memory resource in the B+ tree index through the B+ tree index. Therefore, the above addressing process takes a long time.
  • FIG. 2 shows a schematic structural diagram of a B+ tree provided by an embodiment of the present application.
  • the write operation to the B+ tree is nothing more than inserting and deleting elements.
  • the write operation to the B+ tree is nothing more than inserting and deleting elements.
  • the write operation to the B+ tree is nothing more than inserting and deleting elements.
  • the root node of the tree Root
  • This process starts from the root node of the tree (Root) to start a recursive search until the leaf level node. Assuming that the new element to be inserted is "55”, first find the root node (No. 1 node), through comparison, then enter No. 2 node, and then enter No.
  • Elements may be merged with sibling nodes on the left and right sides, and the merge operation may recurse up to the root node, causing changes in the entire tree structure.
  • this embodiment newly adds a pre-write stage.
  • the process can initiate a pre-write lock application request to the electronic device, so as to execute the required edit element search in the pre-write lock stage. address operation.
  • the read and write parameters provided by the electronic device include pre-written flags and write flags.
  • the pre-write flag can be represented as pw
  • the write flag can be represented as write.
  • the pre-write flag and the write flag are specifically mutually exclusive parameters, and their values have and only have two values, that is, the first bit value and the second bit value. Therefore, the pre-write lock and the write lock Both are mutexes, which can be expressed as: volatile unsigned charpw; volatile unsigned charwrite.
  • the above-mentioned read and write parameters also include a read flag, then the above-mentioned read and write parameters can be specifically expressed as:
  • the above read and write parameters have 3 identification bits:
  • the pre-write flag pw that is, the pre-write lock, is specifically a write lock mutex variable. When it is set to 1, other write operations are excluded, but other processes are allowed to share reads;
  • the write flag write that is, the write lock, is specifically a read lock mutex variable. When it is set to 1, it excludes any other process from reading and writing;
  • Read lock counter which records the number of processes (or threads) currently holding read locks.
  • pre-write flag is the first bit value
  • feed back the pre-write approval instruction to the first process and set the pre-write flag to the second bit value, so that the first A process executes a pre-write operation based on the pre-write lock applied for; when the pre-write flag is at the second bit value, blocking responses to pre-write lock application requests and write requests initiated by other processes except the first process A lock application request, responding to the read lock application request initiated by the other process.
  • the electronic device detects that the pre-write flag is the first value in the read-write parameters of the target data, it means that the current pre-write lock is available, and the first process can be allowed to perform the pre-write operation at this time.
  • Feedback a pre-write approval instruction to the first process that is, send the pre-write lock to the first process, and the first process can perform the pre-write operation according to the pre-write lock obtained after the application, wherein the pre-write operation is specifically for the required editing element
  • the pre-write operation is specifically for the required editing element
  • the electronic device in order to prevent other processes from performing pre-write operations and write operations, the electronic device will configure the pre-write flag in the above-mentioned read and write parameters as the second bit value, that is, perform pre-write lock
  • the lock operation when the pre-write flag is configured as the second value, it will block the response to the pre-write application request and write application request of other threads, but when the above-mentioned pre-write flag is reconfigured to the first value, According to the order of application, the pre-writing application requests and writing application requests initiated by other threads are answered in turn.
  • the locking and unlocking operations corresponding to pre-write locks and write locks can be expressed as: lock(c_mutex_t *) and unlock(c_mutex_t *), where * can be replaced by pre-write
  • * can be replaced by pre-write
  • the value of c_mutex_t is non-zero (that is, the second value)
  • the function __sync_lock_release is used to realize the release function.
  • c_mutex_t The value of 0 (that is, the first value).
  • the first process after the first process completes the pre-writing operation, it can initiate a write lock application request to the electronic device. At this time, the first process has completed the addressing operation of the element, and can directly edit the element. Data editing can be performed on the target data, such as modifying or deleting any element in the target data, or adding new elements to the target data. If the target data is a B+ tree index, the nodes in the B+ tree index can be deleted, modified, or new nodes can be added.
  • the method for controlling data reading and writing adds a corresponding pre-written flag on the basis of the write flag in the read and write parameters, and searches for the data before the thread needs to be executed.
  • a pre-write lock application request can be initiated.
  • the pre-write approval instruction is fed back to the thread, that is, the pre-write lock is applied to the thread.
  • this application can complete the addressing operation through the pre-write lock if the pre-write phase is used before the data is written, and other reads are allowed during the pre-write phase Operation, so that while avoiding conflicts between write operations, it can also reduce the exclusive time for data in the addressing process, and greatly improve the shared reading capability of data.
  • FIG. 3 shows a specific implementation flow chart of a data reading and writing control method S102 provided in the second embodiment of the present application.
  • a data reading and writing control method S103 provided by this embodiment includes: S1031 ⁇ S1034, which are detailed as follows:
  • performing a data editing operation on the target data in response to the write lock application request for the target data initiated by the first process includes:
  • the electronic device can allow other processes to perform the read operation, but in order to avoid data conflicts, in the process of reading the target data, it is not allowed to read the target data For modification, avoid the inconsistency between the read value and the modified value. Based on this, when the first process initiates a write lock application request after completing the pre-write operation, the electronic device needs to re-read the read-write parameters of the target data.
  • the read/write parameter includes a read identification bit.
  • the read flag is the value of the third bit, it means that no other process currently performs a read operation on the target data, that is, no process has a read lock. In this case, Then perform the operation of S1032; otherwise, if the read flag is other than the third position, it means that there is currently a process performing a read operation on the target data, and at this time, perform the operation of S1033.
  • the electronic device when the electronic device receives the write lock application request initiated by the first process, it blocks and responds to the read lock application requests initiated by other processes, that is, other processes are not allowed to perform read operations.
  • the read flag is the third bit value, it means that no other process currently performs the read operation, and the third bit value can be 0, or other preset values.
  • the electronic device A write approval instruction may be fed back to the first process, that is, a lock operation is performed on the write lock, and the write flag bit is configured as the second bit value.
  • the first process may perform a data editing operation on the target data based on the applied write lock. In the state where the write flag is the value of the second bit, all pre-write application requests, write application requests, and read lock application requests for the target data will be blocked and answered, which is a write exclusive operation.
  • the method further includes:
  • the read flag is a bit value other than the third bit value, it means that there are currently other processes performing read operations on the target data, and it is necessary to wait for all the read operations to be completed before performing the write operation. operate.
  • the electronic device may determine the number of processes that are currently performing the read operation according to the read identification bit.
  • a read lock release command can be initiated to the electronic device, and the electronic device can unlock the read lock according to the read lock release command, reducing the number of read flags.
  • Bit value if the electronic device detects that the adjusted read flag is changed to the third bit value, it means that all processes have finished reading, and at this time the write operation can be performed. At this time, a write can be fed back to the first process Enter the consent instruction, so that the first process executes the data editing operation according to the applied write lock.
  • the priority of the write-ahead lock application request is higher than that of the write lock application request; the priority of the write lock application request is higher than that of the read lock application request.
  • FIG. 4 shows a timing diagram of multi-thread concurrency provided by an embodiment of the present application.
  • the electronic device contains 4 processes. According to the read and write operations of the 4 processes on the target data, the bit value of each identification bit in the corresponding read and write parameters (that is, the read-write lock) can be changed. Through the Read-write locks protect target data, such as B+ tree index structures. In a multi-process (or thread) concurrent environment, whether it is to read or write the target data, it is necessary to apply for the lock protected by it first, and only after obtaining the permission of the lock can the resource be accessed.
  • process 1 (which can be equivalent to the first process in the above embodiment) and process 3 need to perform data editing operations on the target data (wherein, process 1 does not determine the address of the element, and process 3 to determine the address of the element), process 2 and process 4 need to read data.
  • process 1 When process 1 needs to edit the target data, because the address of the element has not been determined, it applies to the electronic device for a "pre-write lock", that is, it initiates a pre-write lock application request. At this time, since no other process holds the lock (ie The pre-write lock is the first value in the read-write parameter), so process 1 successfully applies for the "pre-write lock” and enters the pre-write state.
  • Process 2 needs to read data and apply for a "read lock" from the electronic device. Since no other process holds an exclusive write lock at this time, that is, the write flag is the first value. Although process 1 holds a pre-write lock, this Shared reading is still allowed, so process 2 successfully acquires the "read lock” and enters the state of reading data.
  • the number of read locks of the electronic device is 1, that is, the read flag is set to 1.
  • process 3 When process 3 needs to edit the target data, since the element address has been determined, it can directly apply for a "write lock" to the electronic device, that is, initiate a write lock application request, but at this time process 1 holds a "pre-write lock” , so process 3 cannot acquire the write lock immediately and enters the waiting state.
  • Process 1 pre-writing (reading related data) is completed, the target data needs to be formally edited, and a "write lock" is applied to the electronic device, that is, a write lock application request is initiated, that is, the pre-write lock is converted to an exclusive write lock, but this
  • a write lock application request is initiated, that is, the pre-write lock is converted to an exclusive write lock, but this
  • process 2 holds a read lock, the number of read locks is greater than 0, that is, the read flag is not the third value, so process 1 cannot immediately acquire the write lock and enters the waiting state.
  • Process 2 releases the read lock. At this time, the number of read locks in the electronic device is cleared, that is, the read flag is changed to the third value again. Both process 1 and process 3 are in the waiting state, but process 1 already holds the pre-write The lock has a higher priority, so process 1 obtains an exclusive write lock and enters the write state.
  • Process 4 applies for a "read lock" to the electronic device, but process 1 holds an exclusive write lock at this time, so process 4 cannot obtain the read lock immediately and enters a waiting state.
  • Process 1 releases the write lock. At this time, both process 3 and process 4 are in the waiting state, but the write lock has a higher priority than the read lock, so process 3 obtains the write lock first and enters the write state.
  • Process 3 releases the write lock. At this time, only process 4 is in the waiting state, so process 4 obtains the read lock and enters the read state.
  • the number of read locks in the electronic device is 1.
  • Process 4 releases the read lock, and the number of read locks in the electronic device is cleared.
  • FIG. 5 shows a specific implementation flowchart of a method for controlling data reading and writing provided by the third embodiment of the present application.
  • a control method for data reading and writing provided by this embodiment also includes S501 ⁇ S502, which are detailed as follows:
  • the second process can initiate a read lock application request to the electronic device.
  • the electronic device can determine the read and write parameters of the target data and determine whether the read operation is currently allowed.
  • the write flag is the first bit value, it means that there is no exclusive write lock at present, and no matter whether there is a pre-write lock, the read operation can be performed.
  • the second process can Feedback the read consent command, that is, the second process obtains the read lock, can perform a read operation on the target data, and increase the bit value of the read flag to record the number of processes currently performing the read operation.
  • the implementation process of the write-ahead lock for reading elements in the B+ tree is as follows:
  • the second process applies to the electronic device to add a read lock to the B+ tree, that is, a read lock application request;
  • the second process starts to search the B+ tree, starting from the root node, to find the leaf node where the element is located and location;
  • the bit value of the write flag is read to determine whether there is currently a process performing a data editing operation, thereby ensuring the accuracy of the read operation.
  • FIG. 6 shows a specific implementation flowchart of a method for controlling data reading and writing provided by the fourth embodiment of the present application.
  • a method for controlling data reading and writing provided by this embodiment further includes: S601 ⁇ S602, which are described in detail as follows:
  • the third process when it has determined the address of the element to be edited in the target data, it can initiate a write lock application request to the electronic device.
  • the electronic device needs to determine whether there is currently a process holding a pre-write lock And an exclusive write lock, and determine whether there is a process holding a read lock, that is, in the read and write parameters, the pre-write flag and the write flag are the first value, and the read flag is the third value, if all satisfy If the above conditions are met, then in response to the write lock application request, the third process is allowed to perform the write operation. On the contrary, if any of the above conditions are not met, it needs to wait.
  • FIG. 7 shows a specific implementation flowchart of a method for controlling data reading and writing provided by the fifth embodiment of the present application.
  • a method for controlling data reading and writing provided by this embodiment further includes: S701 to S702 , which are described in detail as follows:
  • the first process may determine whether to directly initiate a write lock application request or a pre-write lock application request according to whether the element address is determined. Since determining the element address requires a certain amount of addressing time, it is not necessary to apply for an exclusive write lock during the addressing process, but to apply for a pre-write lock, which can improve the ability to share data reads.
  • FIG. 8 shows a specific implementation flowchart of a method for controlling data reading and writing provided by the sixth embodiment of the present application.
  • a method for controlling data reading and writing provided by this embodiment further includes: S801 to S803 , which are described in detail as follows:
  • the target data is a B+ tree index
  • the data editing operation is a deletion operation on a target element in the target data
  • the pre-writing identification bit is the first bit value, feeding back the pre-writing approval instruction to the first process, and setting the pre-writing identification bit as the second bit value, it also includes:
  • the above-mentioned data editing operation is specifically to delete the nodes in the B+ tree index.
  • the above-mentioned implementation process may specifically include the following steps:
  • the first process can apply to the electronic device to add a pre-write lock to the B+ tree, that is, a pre-write lock application request.
  • the electronic device After the first process receives the pre-write lock application success instruction fed back by the electronic device (the electronic device will set the pre-write flag pw in the read and write parameters to 1, and the write flag is 0 at this time), it will start to edit the B+ tree Retrieve, starting from the root node, find the leaf node and position where the element to be deleted is located, that is, the pre-write operation.
  • step d If the first process fails to find, that is, the element does not exist, the pre-write lock is released, and the process is terminated; otherwise, it enters step d).
  • the first process obtains the location information of the target element, it applies to the electronic device for converting the pre-write lock into an exclusive write lock.
  • the process of inserting elements specifically includes the following steps:
  • the first process first applies to the electronic device for adding a pre-write lock to the B+ tree;
  • the first process releases the write lock (both pw and write in the read and write parameters are set to 0), and the element insertion process is completed.
  • FIG. 9 shows a structural block diagram of a data reading and writing control device provided by an embodiment of the present application.
  • the units included in the data reading and writing control device are used to execute the steps in the embodiment corresponding to FIG. 1 .
  • FIG. 1 and related descriptions in the embodiment corresponding to FIG. 1 For ease of description, only the parts related to this embodiment are shown.
  • control device for reading and writing data includes:
  • the pre-write lock application unit 91 is configured to determine the read-write parameters of the target data in response to the pre-write lock application request for the target data initiated by the first process; the read-write parameters include a pre-write flag and a write flag ;
  • the pre-writing trigger unit 92 is configured to feed back a pre-writing approval instruction to the first process if the pre-writing flag is a first bit value, and set the pre-writing flag to a second bit value, so as to Make the first process perform a pre-write operation based on the applied-for write-ahead lock; when the pre-write flag is at the second bit value, block the pre-write lock application initiated by other processes except the first process Request and write lock application request;
  • a write lock application unit 93 configured to perform a data editing operation on the target data in response to a write lock application request for the target data initiated by the first process; It is initiated after the process completes the pre-write operation.
  • the pre-writing trigger unit 92 includes:
  • a write lock application request response unit configured to determine the read and write parameters of the target data in response to the write lock application request; the read and write parameters include a read flag;
  • the write lock execution unit Agree to the write lock execution unit, for if the read flag is the third bit value, feed back the write consent command to the first process, and set the write flag to the second bit value, so that The first process executes a data editing operation based on the applied write lock; when the write flag is at the second bit value, it blocks and responds to other processes to initiate a pre-write lock application request, a write lock application request, and a read lock application request .
  • control device also includes:
  • a read operation waiting unit configured to determine the number of processes currently performing a read operation based on the read flag if the read flag is a bit value other than the third bit value;
  • the read operation waiting completion unit is configured to adjust the bit value of the read flag in response to the read lock release instruction fed back by other processes that perform the read operation, until the adjusted read flag is the third bit value, Then execute the feedback write approval instruction to the first process, and set the write flag to the second bit value.
  • control device also includes:
  • a read lock application unit configured to determine the read and write parameters of the target data in response to the read lock application request for the target data initiated by the second process; the read and write parameters also include a read flag;
  • a read lock application consent unit configured to feed back a read consent instruction to the second process if the write flag is the first bit value, and increase the read flag so that the second process based on The requested read lock executes the read operation.
  • control device also includes:
  • a write lock application unit configured to determine the read and write parameters of the target data in response to the write lock application request for the target data initiated by the third process; the read and write parameters also include a read flag;
  • a write lock application approval unit configured to feed back a write consent instruction to the third process if the pre-write flag and the write flag are the first bit value, and the read flag is the third bit value, and Setting the write flag bit to a second bit value, so that the third process performs a data editing operation on the target data.
  • control device also includes:
  • An element address pending unit configured to initiate the write-ahead lock application request through the first process if the element address of the data editing operation has not been determined
  • the element address known unit is configured to initiate a write lock application request through the first process if the element address of the data editing operation has been determined.
  • the target data is a B+ tree index
  • the data editing operation is a deletion operation on a target element in the target data
  • the control device also includes:
  • a location information query unit configured to query the location information of the target element in the B+ tree index through the first process
  • a write-ahead lock releasing unit configured to release the write-ahead lock applied for through the first process if the location information of the target element is not queried in the B+ tree index, and transfer the write-ahead lock to the
  • the write identification bit is configured as the first bit value
  • a location confirmation unit configured to initiate the write lock application request through the first process if the location information of the target element is found in the B+ tree index.
  • Another embodiment of the present application also provides a data read and write control device, which is used to allocate pre-write locks, write locks, and read locks according to read-write parameters, wherein the read-write parameters include: pre-write flags, write flags bits and read flags;
  • the pre-write flag is the first bit value, it is allowed to respond to the pre-write application request initiated by the thread, so as to distribute the pre-write lock to the process that initiated the pre-write application request, and after assigning the pre-write lock to any process, Setting the pre-written identification bit as the second bit value;
  • the pre-write identification bit is the second bit value
  • the pre-write application request and the write application request initiated by the response thread are blocked, and the read application request inspired by the response thread is allowed.
  • the control device for reading and writing data is also used for:
  • the write flag and the pre-write lock are both the first bit value, it is allowed to respond to the write application request initiated by the thread, and when the read flag bit is the third bit value, it is allocated to the process that initiated the write application request write lock, and after assigning a write lock to any process, the write flag is set to the second value;
  • the pre-write application request, write application request and read application request initiated by the response thread are blocked.
  • the control device for reading and writing data is also used for:
  • the read identification bit is the third bit value, it is allowed to respond to the write application request initiated by the thread;
  • the write identification bit When the write identification bit is the first bit value, it is allowed to respond to the read application request initiated by the process, and allocate a read lock to the process that initiated the read application request, and configure the read identification bit according to the number of allocated read locks.
  • the electronic device provided by the embodiment of the present application can also add a corresponding pre-written flag on the basis of the write flag in the read-write parameter, and when the thread needs to perform a write operation that is addressed first, A pre-write lock application request can be initiated, and when it is detected that the pre-write flag is at the first value, a pre-write approval instruction is fed back to the thread, that is, the pre-write lock is applied to the thread, and the pre-write operation can be performed;
  • the thread can complete the addressing task and allow other processes to read the target data, and after the addressing is completed, the process can initiate a write lock application request, and based on the execution of subsequent data editing operations, that is, the target The data is written to realize concurrent operations on the same target data.
  • this application can complete the addressing operation through the pre-write lock if the pre-write phase is used before the data is written, and other reads are allowed during the pre-write phase Operation, so that while avoiding conflicts between write operations, it can also reduce the exclusive time for data in the addressing process, and greatly improve the shared reading capability of data.
  • Fig. 10 is a schematic diagram of an electronic device provided by another embodiment of the present application.
  • the electronic device 10 of this embodiment includes: a processor 100, a memory 101, and a computer program 102 stored in the memory 101 and operable on the processor 100, such as the control of data reading and writing program.
  • the processor 100 executes the computer program 102, it implements the steps in the embodiments of the control method for reading and writing data above, such as S101 to S103 described in FIG. 1 .
  • the processor 100 executes the computer program 102
  • the functions of the units in the above-mentioned device embodiments are implemented, for example, the functions of the modules 91 to 93 in FIG. 9 .
  • the computer program 102 may be divided into one or more units, and the one or more units are stored in the memory 101 and executed by the processor 100 to complete the present application.
  • the one or more units may be a series of computer program instruction segments capable of accomplishing specific functions, and the instruction segments are used to describe the execution process of the computer program 102 in the electronic device 10 .
  • the electronic device may include, but not limited to, a processor 100 and a memory 101 .
  • FIG. 10 is only an example of the electronic device 10, and does not constitute a limitation to the electronic device 10. It may include more or fewer components than shown in the figure, or combine some components, or different components. , for example, the electronic device may also include an input and output device, a network access device, a bus, and the like.
  • the so-called processor 100 may be a central processing unit (Central Processing Unit, CPU), and may also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • the storage 101 may be an internal storage unit of the electronic device 10 , such as a hard disk or memory of the electronic device 10 .
  • the memory 101 may also be an external storage device of the electronic device 10, such as a plug-in hard disk equipped on the electronic device 10, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, flash memory card (Flash Card), etc.
  • the memory 101 may also include both an internal storage unit of the electronic device 10 and an external storage device.
  • the memory 101 is used to store the computer program and other programs and data required by the electronic device.
  • the memory 101 can also be used to temporarily store data that has been output or will be output.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Hardware Redundancy (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请适用于数据处理技术领域,提供了一种数据读写的控制方法及电子设备,包括:响应于第一进程发起的对于目标数据的预写锁申请请求,确定所述目标数据的读写参量;若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值,以使所述第一进程基于申请的预写锁执行预写操作;响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作。采用本申请能够在避免写入操作间相互冲突的同时,还能够减少寻址过程中对于数据的独占时长,大大提高了数据的共享读取能力。

Description

一种数据读写的控制方法及电子设备
本申请要求于2021年12月31日在中国专利局提交的、申请号为202111679116.9的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请属于数据处理技术领域,尤其涉及一种数据读写的控制方法及电子设备。
背景技术
随着电子技术的不断发展,越来越多的信息通过电子化的形式存储,大大提高了信息编辑以及传递的效率。近年来随着云技术的应用,能够实现多人同时对同一数据的操作,也进一步提高了电子化数据的编辑效率。然而,多进程同时对同一数据进行操作时,虽然提高了数据编辑的效率,但也同时带来了新的问题,即不同进程间的写入操作会存在相互冲突的情况。
现有的数据读写的控制技术,为了确保编辑数据的准确性以及避免对同一数据的写入冲突,可以配置读写锁,以便对于同一数据而言有且只有一个写入操作,并且在写入操作时阻塞其他对于该数据的读取操作。然而,若某一数据的数据量较大,进行写入操作时需要消耗较长时间完成对编辑元素的寻址动作,而在寻址过程中阻塞读取操作,则大大降低了对于数据的读写效率,并发效率较低。
技术问题
有鉴于此,本申请实施例提供了一种数据读写的控制方法及电子设备,以解决现有的数据读写的控制技术,若某一数据的数据量较大,进行写入操作时需要消耗较长时间完成对编辑元素的寻址动作,而在寻址过程中阻塞读取操作,则大大降低了对于数据的读写效率,并发效率较低的问题。
技术解决方案
本申请实施例的第一方面提供了一种数据读写的控制方法,包括:
响应于第一进程发起的对于目标数据的预写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含预写标识位以及写标识位;
若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值,以使所述第一进程基于申请的预写锁执行预写操作;在所述预写标识位处于所述第二位值时,阻塞应答除所述第一进程外的其他进程发起的预写锁申请请求以及写锁申请请求,应答所述其他进程发起读锁申请请求;
响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作;所述写锁申请请求是在所述第一进程执行完成所述预写操作后发起的。
在第一方面的第一种可能的实现方式中,所述响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作,包括:
响应于所述写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含读标识位;
若所述读标识位为所述第三位值,则向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值,以使所述第一进程基于申请的写锁执行数据编辑操作;在所述写标识位处于所述第二位值时,阻塞应答其他进程发起预写锁申请请求、写锁申请请求以及读锁申请请求。
在第一方面的第一种可能的实现方式中,在所述响应于所述写锁申请请求,确定所述目标数据的读写参量之后,还包括:
若所述读标识位为除所述第三位值外的其他位值,则基于所述读标识位确定当前执行读取操作的进程个数;
响应于执行读取操作的其他进程反馈的读锁释放指令,调整所述读标识位的位值,直到调整后的读标识位为所述第三位值时,则执行所述向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值。
在第一方面的第一种可能的实现方式中,还包括:
响应于第二进程发起的对于所述目标数据的读锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位;
若所述写标识位为所述第一位值,则向所述第二进程反馈读同意指令,并增加所述读标识位,以使所述第二进程基于申请的读锁执行读取操作。
在第一方面的第一种可能的实现方式中,还包括:
响应于第三进程发起的对于所述目标数据的写锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位;
若所述预写标识位以及写标识位为第一位值,且所述读标识位为第三位值,则向所述第三进程反馈写同意指令,并将所述写标识位设置为第二位值,以使所述第三进程对所述目标数据执行数据编辑操作。
在第一方面的第一种可能的实现方式中,在所述响应于第一进程发起的对于目标数据的预写锁申请请求之前,还包括:
若未确定所述数据编辑操作的元素地址,则通过所述第一进程发起所述预写锁申请请求;
若已确定所述数据编辑操作的元素地址,则通过所述第一进程发起写锁申请请求。
在第一方面的第一种可能的实现方式中,所述目标数据为B+树索引;所述数据编辑操作为对所述目标数据内的目标元素的删除操作;
在所述若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值之后,还包括:
通过所述第一进程查询所述目标元素在所述B+树索引内位置信息;
若在所述B+树索引内未查询到所述目标元素的所述位置信息,则通过所述第一进程释放申请的所述预写锁,并将所述预写标识位配置为所述第一位值;
若在所述B+树索引内查询到所述目标元素的所述位置信息,则通过所述第一进程发起所述写锁申请请求。
在第一方面的一种可能的实现方式中,所述预写锁申请请求的优先级高于写锁申请请求的优先级;所述写锁申请请求的优先级高于读锁申请请求的优先级。
本申请实施例的第二方面提供了一种数据读写的控制装置,包括:
预写锁申请单元,用于响应于第一进程发起的对于目标数据的预写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含预写标识位以及写标识位;
预写触发单元,用于若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值,以使所述第一进程基于申请的预写锁执行预写操作;在所述预写标识位处于所述第二位值时,阻塞除所述第一进程外的其他进程发起的预写锁申请请求以及写锁申请请求;
写锁申请单元,用于响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作;所述写锁申请请求是在所述第一进程执行完成所述预写操作后发起的。
本申请实施例的第三方面还提供了一种数据读写的控制装置,用于根据读写参量分配预写锁、写锁以及读锁,其中,读写参量包括:预写标识位、写标识位以及读标识位;
在所述预写标识位为第一位值时,允许应答线程发起的预写申请请求,以向发起预写申请请求的进程分配预写锁,并在给任一进程分配预写锁后,将所述预写标识位设置为第二位值;
在所述预写标识位为第二位值时,阻塞应答线程发起的预写申请请求以及写申请请求,允许应答线程启发的读申请请求。
在第三方面的一种可能的实现方式中,所述数据读写的控制装置还要用于:
在所述写标识以及所述预写锁均为第一位值时,允许应答线程发起的写申请请求,并在所述读标识位为第三位值时以向发起写申请请求的进程分配写锁,并在给任一进程分配写锁后,将所述写标识位设置为第二位值;
在所述写标识位为第二位值时,阻塞应答线程发起的预写申请请求、写申请请求以及读申请请求。
在第三方面的一种可能的实现方式中,所述数据读写的控制装置还用于:
在所述读标识位为第三位值时,允许应答线程发起的写申请请求;
在所述写标识位为第一位值时,允许应答进程发起的读申请请求,并向发起读申请请求的进程分配读锁,并根据分配的读锁个数配置读标识位。
本申请实施例的第三方面提供了一种电子设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现第一方面的各个步骤。
本申请实施例的第四方面提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现第一方面的各个步骤。
有益效果
实施本申请实施例提供的一种数据读写的控制方法及电子设备具有以下有益效果:
本申请实施例通过在读写参量中在写标识位的基础上,添加有对应的预写标识位,并在线程需要执行先进行寻址的写入操作时,可以发起一个预写锁申请请求,在检测到预写标识位处于第一位值时,向该线程反馈预写同意指令,即向该线程申请得到预写锁,可以执行预写操作;在预写操作过程中,该线程可以完成寻址任务,并允许其他进程读取目标数据,并在寻址完成后,该进程可以发起写锁申请请求,并基于执行后续的数据编辑操作,即对目标数据进行写入操作,实现了对同一目标数据的并发操作。与现有的数据读写的控制技术相比,本申请在对数据进行写入操作之前,假如了预写阶段,进程可以通过预写锁完成寻址操作,并且在预写阶段允许其他读取操作,从而能够在避免写入操作间相互冲突的同时,还能够减少寻址过程中对于数据的独占时长,大大提高了数据的共享读取能力。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1是本申请第一实施例提供的一种数据读写的控制方法的实现流程图;
图2是本申请一实施例提供的B+数索引的结构示意图;
图3是本申请第二实施例提供的一种数据读写的控制方法S103具体实现流程图;
图4是本申请一实施例提供的多线程并发的时序示意图;
图5是本申请第三实施例提供的一种数据读写的控制方法具体实现流程图;
图6是本申请第四实施例提供的一种数据读写的控制方法具体实现流程图;
图7是本申请第五实施例提供的一种数据读写的控制方法具体实现流程图;
图8是本申请第六实施例提供的一种数据读写的控制方法具体实现流程图;
图9是本申请一实施例提供的一种数据读写的控制装置的结构框图;
图10是本申请一实施例提供的一种电子设备的示意图。
本发明的实施方式
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请实施例通过在读写参量中在写标识位的基础上,添加有对应的预写标识位,并在线程需要执行先进行寻址的写入操作时,可以发起一个预写锁申请请求,在检测到预写标识位处于第一位值时,向该线程反馈预写同意指令,即向该线程申请得到预写锁,可以执行预写操作;在预写操作过程中,该线程可以完成寻址任务,并允许其他进程读取目标数据,并在寻址完成后,该进程可以发起写锁申请请求,并基于执行后续的数据编辑操作,即对目标数据进行写入操作,实现了对同一目标数据的并发操作,解决了数据读写的控制技术,若某一数据的数据量较大,进行写入操作时需要消耗较长时间完成对编辑元素的寻址动作,而在寻址过程中阻塞读取操作,则大大降低了对于数据的读写效率,并发效率较低的问题。
本申请实施例提供的异常请求的识别方法可以应用于智能手机、服务器、平板电脑、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、服务器等电子设备上。本申请实施例对电子设备的具体类型不作任何限制。特别地,该电子设备具体为一云端服务器,该云端服务器存储有至少一个共享数据,根据提供服务类型不同,上述云端服务器可以包括如云文档、云计算、云应用以及云内存等提供云服务的服务器。该服务器可以接收各个终端发起的对于目标数据的操作(若该云服务为云文档,则上述目标数据具体为一电子文档;若该云服务为云内容,则上述目标数据可以为对于确定内存的地址的索引表),服务器可以为不同终端发起的操作配置对应的进程,以实现共享目标数据的目的。
请参阅图1,图1示出了本申请第一实施例提供的数据读写的控制方法的实现流程图,详述如下:
在S101中,响应于第一进程发起的对于目标数据的预写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含预写标识位以及写标识位。
在本实施例中,用户在需要对目标数据进行编辑时,如需要对目标数据内的某一元素进行修改、新增或删除时,可以通过对应的终端向电子设备发起一个预写锁申请请求。其中,电子设备可以为不同的终端配置一条进程,终端可以通过分配的进程对目标数据进行读取以及写入等操作,在该情况下,则电子设备具体是通过终端所分配的进程接收终端发起的请求,因此,在终端需要对目标数据进行预写操作时,可以通过与其对应的第一进程向电子设备发起预写申请请求。
在本实施例中,每个进程可以根据是否已确定所需写入元素的地址,来确定该进程是否需要执行预写操作。若某一进程已确定所需写入的元素的地址,则该进程可以直接执行写操作,而无需进行预写操作,在该情况下,第一进程可以发起一个写锁申请请求,以直接执行数据编辑操作;反之,若某一进程未确定时所需写入的元素的地址,即需要进行寻址,则该进程需要执行预写操作后,再执行写操作,基于此,第一进程需要发起预写锁申请请求,以在预写阶段确定所需写入的元素的地址,并在确定元素的地址后再申请写锁。
由于提供云服务的过程中,若目标数据的数据量较大,则寻址过程并非瞬时完成的,以提供共享内存服务为例,共享内容数据库配置有一基于B+树构建的索引表,各个进程可以通过B+树索引确定各个内存资源在上述B+树索引内对应的节点以及位置,才能够完成对于内存资源的寻址,因此,上述寻址过程耗时较大。
示例性地,图2示出了本申请一实施例提供的B+树的结构示意图。参见图2所示,对B+树的写入操作,无外乎就是***元素和删除元素。根据B+树的性质,当进程需要向B+树的索引表内***一个新元素时,则需要确定该新元素需要***到哪个叶子节点(Leaf)的哪个位置上,这个过程是从树的根节点(Root)开始进行递归查找,直至叶子级节点为止。假设***的新元素为“55”,首先找到根节点(即1号节点)上,通过比较,然后进入2号节点,再进入6号节点(查找的路径见加粗箭头),通过比较发现该元素需要***到6号节点的第二个位置上。在进程找到***位置后,才能将新元素***合适叶子节点的正确位置上,***元素后,如果叶子节点违反了B+树的平衡性质,则需要***成相邻的两个兄弟节点,***操作可能递归直至根节点,引起树结构发生变化。从B+树中删除元素时,同样需要先找到元素所在的叶子节点及位置,找到了才能在相应叶子节点中做删除操作,删除元素之后,如果叶子节点违反了B+树的平衡性质,则需要借调元素或与左右两边的兄弟节点进行合并,合并操作可能递归直至根节点,引起整个树结构发生变化。从以上的分析可以看出,无论是***元素还是删除元素,在进程对B+树索引进行写入操作之前,若不确定该元素对应的节点位置,都存在一个从根节点到叶子节点递归查找的过程,这个阶段只是一个纯粹的读数据过程,不会写入任何数据,即索引表并不会发生实际性修改,无需阻塞所有读操作。同时,在一个大型的B+树索引中查找一个元素的耗时相对于在已经确定了节点地址的读取操作而言,所需的耗时完全不是一个量级的,即查找操作比基于地址进行读取操作而言时间要多得多,因此,若在查找阶段阻塞所有读取操作,则会大大降低了数据并发的能力。因此,为了解决上述问题,本实施例新加入了预写阶段,在需要确定元素地址时,进程可以向电子设备发起一个预写锁申请请求,以便在预写锁阶段执行所需编辑的元素寻址操作。
在本实施例中,该电子设备可以提供的读写参量内包含有预写标识位以及写标识位。其中,预写标识位可以表示为pw,而写标识位可以表示为write,在电子设备接收到第一进程发起的预写锁申请请求时,需要确定当前是否存在其他进程占用了预写锁或者写锁,则需要确定预写标识位以及写标识位对应的位值,即确定上述读写参量的状态。
在本实施例中,预写标识位以及写标识位具体均为互斥参量,其值有且只有两种取值,即第一位值以及第二位值,因此,预写锁以及写锁均为互斥锁,可以表示为:volatile unsigned charpw;volatile unsigned charwrite。
在一种可能的实现方式中,上述读写参量还包含读标识位,则上述读写参量具体可以表示为:
typedef struct
{
             volatile unsigned charpw;       // 排斥写的标记
             volatile unsigned charwrite;     // 排斥读的标记
             volatile unsigned int  read;     // 读锁数量
}rwlock_t;
其中,上述读写参量有3个标识位:
预写标识位pw,即预写锁,具体为一写锁互斥变量,被设置为1时,排斥其它写操作进入,但允许其他进程共享读;
写标识位write,即写锁,具体为一读锁互斥变量,被设置为1时,排斥其他任何进程进行读和写两种操作;
read:读锁记数器,记录当前持有读锁的进程(或线程)数。
在S102中,若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值,以使所述第一进程基于申请的预写锁执行预写操作;在所述预写标识位处于所述第二位值时,阻塞应答除所述第一进程外的其他进程发起的预写锁申请请求以及写锁申请请求,应答所述其他进程发起读锁申请请求。
在本实施例中,电子设备若检测到目标数据的读写参量中,预写标识位为第一位值,则表示当前的预写锁可用,此时可以允许第一进程执行预写操作,向该第一进程反馈一个预写同意指令,即将预写锁发送给第一进程,第一进程可以根据申请得到的预写锁执行预写操作,其中,预写操作具体为对所需编辑元素进行寻址的操作,具体过程可以参见S101的相关描述。
在本实施例中,电子设备为了避免其他进程再执行预写操作以及写操作,在该情况下,会将上述读写参量中的预写标识位配置为第二位值,即进行预写锁的加锁操作,在预写标识位配置为第二位值时,会阻塞应答其他线程的预写申请请求以及写申请请求,而是知道上述预写标识位重新配置为第一位值时,才根据申请的先后次序,依次应答其他线程发起的预写申请请求以及写申请请求。
在一种可能的实现方式中,而对于预写锁以及写锁对应的加锁以及解锁操作,可以表示为:lock(c_mutex_t *)和unlock(c_mutex_t *),其中*号具体可以替换为预写锁以及写锁对应的标识,利用函数__sync_bool_compare_and_swap来实现加锁功能,加锁成功之后c_mutex_t的值为非0(即第二位值),用函数__sync_lock_release来实现释放锁功能,释放锁之后c_mutex_t的值为0(即第一位值)。
在S103中,响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作;所述写锁申请请求是在所述第一进程执行完成所述预写操作后发起的。
在本实施例中,第一进程在执行完成预写操作后,可以向电子设备发起一个写锁申请请求,此时,第一进程已经完成了元素的寻址操作,可以直接对元素进行编辑,可以对目标数据进行数据编辑,如对目标数据内的任一元素进行修改、删除,或对目标数据内增加新的元素。若该目标数据为一B+树索引,则可以对该B+树索引内的节点进行删除、修改,或增加新的节点等。
以上可以看出,本申请实施例提供的一种数据读写的控制方法通过在读写参量中在写标识位的基础上,添加有对应的预写标识位,并在线程需要执行先进行寻址的写入操作时,可以发起一个预写锁申请请求,在检测到预写标识位处于第一位值时,向该线程反馈预写同意指令,即向该线程申请得到预写锁,可以执行预写操作;在预写操作过程中,该线程可以完成寻址任务,并允许其他进程读取目标数据,并在寻址完成后,该进程可以发起写锁申请请求,并基于执行后续的数据编辑操作,即对目标数据进行写入操作,实现了对同一目标数据的并发操作。与现有的数据读写的控制技术相比,本申请在对数据进行写入操作之前,假如了预写阶段,进程可以通过预写锁完成寻址操作,并且在预写阶段允许其他读取操作,从而能够在避免写入操作间相互冲突的同时,还能够减少寻址过程中对于数据的独占时长,大大提高了数据的共享读取能力。
图3示出了本申请第二实施例提供的一种数据读写的控制方法S102的具体实现流程图。参见图3,相对于图1所述实施例,本实施例提供的一种数据读写的控制方法S103包括: S1031~S1034,具体详述如下:
进一步地,所述响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作,包括:
在S1031中,响应于所述写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含读标识位。
在本实施例中,由于第一进程在执行预写操作的过程中,电子设备可以允许其他进程执行读操作,而为了避免数据冲突,在目标数据读取的过程中,是不允许对目标数据进行修改的,避免读取得到的值与修改后的值不一致。基于此,第一进程在完成预写操作后发起写锁申请请求时,电子设备需要重新读取目标数据的读写参量。其中,该读写参量中包含有读标识位。
在本实施例中,若该读标识位为第三位值的情况下,则表示当前并没有其他进程对目标数据执行读取操作,即并未有任何进程有读锁,在该情况下,则执行S1032的操作;反之,若该读标识位为第三位置外的其他位值,则表示当前存在进程对目标数据执行读取操作,此时,执行S1033的操作。
在一种可能的实现方式中,在电子设备接收到第一进程发起的写锁申请请求时,会阻塞应答其他进程发起的读锁申请请求,即不允许其他进程再执行读操作。
在S1032中,若所述读标识位为所述第三位值,则向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值,以使所述第一进程基于申请的写锁执行数据编辑操作;在所述写标识位处于所述第二位值时,阻塞应答其他进程发起预写锁申请请求、写锁申请请求以及读锁申请请求。
在本实施例中,若读标识位为第三位值,则表示当前并未有其他进程执行读取操作,该第三位值可以为0,或其他预设的数值,此时,电子设备可以向第一进程反馈写入同意指令,即对写锁进行加锁操作,将写标识位配置为第二位值。第一进程在接收到写入同意指令后,可以基于申请的写锁对目标数据进行数据编辑操作。在写标识位为第二位值的状态下,会阻塞应答所有对目标数据的预写申请请求、写申请请求以及读锁申请请求,即为写独占操作。
进一步地,在所述响应于所述写锁申请请求,确定所述目标数据的读写参量之后,还包括:
在S1033中,若所述读标识位为除所述第三位值外的其他位值,则基于所述读标识位确定当前执行读取操作的进程个数。
在本实施例中,若该读标识位为除第三位值外的其他位值,则表示当前存在其他进程对于目标数据执行读取操作,需要等待所有读操作完成后,才能够执行写入操作。在该情况下,电子设备可以根据读标识位确定当前正在执行读取操作的进程个数。
在S1034中,响应于执行读取操作的其他进程反馈的读锁释放指令,调整所述读标识位的位值,直到调整后的读标识位为所述第三位值时,则执行所述向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值。
在本实施例中,在其他进程执行完成读取操作后,可以向电子设备发起一个读锁释放指令,电子设备可以根据该读锁释放指令对读锁进行解锁操作,减少该读取标识位的位值,若电子设备检测到调整后的读标识位变更为第三位值时,则表示所有进程已经读取完毕,此时可以执行写入操作,此时,可以向第一进程反馈一个写入同意指令,以便第一进程根据申请的写锁执行数据编辑操作。
在本实施例中,所述预写锁申请请求的优先级高于写锁申请请求的优先级;所述写锁申请请求的优先级高于读锁申请请求的优先级。
示例性地,图4示出了本申请一实施例提供的多线程并发的时序示意图。参见图4所示,电子设备内包含有4个进程,根据4个进程对于目标数据的读写操作,可以变更对应的读写参量(即读写锁)内各个标识位的位值,通过该读写锁保护目标数据,比如B+树索引结构。在多进程(或线程)并发环境中,无论是对目标数据进行读操作还是写操作,都需要先向受其保护的锁进行申请,只有获得锁的允许之后才能访问资源。如图4给出的例子所示,进程1(可以相当于上述实施例中的第一进程)和进程3是需要对目标数据进行数据编辑操作(其中,进程1未确定元素的地址,而进程3以确定了元素的地址),进程2和进程4是需要读取数据的。总共有9个读写操作序列,其时序对应于右边的标记的数字0~9。
下面对图中的操作时序进行分析:
1)进程1需要对目标数据进行数据编辑时,由于未确定元素地址,因此向电子设备申请“预写锁”,即发起预写锁申请请求,此时由于没有其它任何进程持有锁(即读写参量中预写锁为第一位值),因此进程1申请“预写锁”成功,进入预写状态。
2)进程2需要读取数据,向电子设备申请“读锁”,由于此时没有其它进程持有独占写锁,即写标识位为第一位值,虽然进程1持有预写锁,此时仍然允许共享读,因此进程2获取“读锁”成功,进入读数据状态,电子设备的读锁数量为1,即将读标识位配置为1。
3)进程3需要对目标数据进行数据编辑时,由于已确定元素地址,因此可以直接向电子设备申请“写锁”,即发起写锁申请请求,但此时进程1持有“预写锁”,因此进程3不能立即获取写锁,进入等待状态。
4)进程1预写(读取相关数据)完成,需要正式对目标数据进行编辑,向电子设备申请“写锁”,即发起写锁申请请求,即由预写锁转独占写锁,但此时进程2持有读锁,读锁数量大于0,即读标识位并非第三位值,所以进程1不能立即获取写锁,进入等待状态。
5)进程2释放读锁,此时电子设备中的读锁数量清零,即读标识位重新变更为第三位值,进程1和进程3都处于等待状态,但进程1已经持有预写锁,优先级更高,所以进程1获得独占写锁,进入写状态。
6)进程4向电子设备申请“读锁”,但此时进程1持有独占写锁,因此进程4不能立即获取读锁,进入等待状态。
7)进程1释放写锁,此时进程3和进程4都处于等待状态,但该写锁是优先级高于读锁,所以进程3优先获得写锁,进入写状态。
8)进程3释放写锁,此时只有进程4处于等待状态,因此进程4获得读锁,进入读状态,电子设备中读锁数量为1。
9)进程4释放读锁,电子设备中读锁数量清零。
在本申请实施例中,在响应进程的写入操作之前,需要先确定当前是否存在进程执行读取操作,从而能够确保读取操作的准确性的同时,也能够实现在预写阶段的读共享,提高了数据的并发性。
图5示出了本申请第三实施例提供的一种数据读写的控制方法的具体实现流程图。参见图5,相对于图1所述实施例,本实施例提供的一种数据读写的控制方法还包括S501~S502,具体详述如下:
在S501中,响应于第二进程发起的对于所述目标数据的读锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位。
在本实施例中,在需要读取目标数据时,第二进程可以向电子设备发起一个读锁申请请求,此时,电子设备可以确定目标数据的读写参量,判断当前是否允许读取操作。
在S502中,若所述写标识位为所述第一位值,则向所述第二进程反馈读同意指令,并增加所述读标识位,以使所述第二进程基于申请的读锁执行读取操作。
在本实施例中,若该写标识位为第一位值,则表示当前并不存在任何独占写锁,不论是否存在预写锁,均可以执行读取操作,此时,可以向第二进程反馈读同意指令,即第二进程获取得到读锁,可以对目标数据执行读取操作,并增加读标识位的位值,以记录当前执行读取操作的进程个数。
示例性地,若目标数据为一B+树索引,则B+树中读取元素的预写锁实现过程具体如下:
a)   首先第二进程向电子设备申请对B+树加读锁,即读锁申请请求;
b)   电子设备申请读锁成功之后(读标识位增1,此时写标识位为第一位值),即第二进程开始对B+树进行检索,从根节点开始,查找元素所在的叶子节点和位置;
c)   第二进程查找完成之后(即读取完成后),无论结果如何,都释放读锁(锁的read减1),流程结束。
在本申请实施例中,通过在接收到读锁申请请求时,读取写标识位的位值,判断当前是否存在进程执行数据编辑操作,从而能够确保读取操作的准确性。
图6示出了本申请第四实施例提供的一种数据读写的控制方法的具体实现流程图。参见图6,相对于图1所述实施例,本实施例提供的一种数据读写的控制方法还包括: S601~S602,具体详述如下:
在S601中,响应于第三进程发起的对于所述目标数据的写锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位。
在S602中,若所述预写标识位以及写标识位为第一位值,且所述读标识位为第三位值,则向所述第三进程反馈写同意指令,并将所述写标识位设置为第二位值,以使所述第三进程对所述目标数据执行数据编辑操作。
在本实施例中,第三进程已经确定了目标数据中所需编辑的元素的地址时,可以向电子设备发起写锁申请请求,此时,电子设备需要确定当前是否存在进程持有预写锁以及独占写锁,以及确定是否存在进程持有读锁,即读写参量中,预写标识位以及写标识位为第一位值,且所述读标识位为第三位值,若均满足上述条件,则响应该写锁申请请求,同意第三进程执行写操作。反之,若不满足任一上述条件,则需要进行等待。
图7示出了本申请第五实施例提供的一种数据读写的控制方法的具体实现流程图。参见图7,相对于图1~6任一项所述实施例,本实施例提供的一种数据读写的控制方法还包括: S701~S702,具体详述如下:
在所述响应于第一进程发起的对于目标数据的预写锁申请请求之前,还包括:
在S701中,若未确定所述数据编辑操作的元素地址,则通过所述第一进程发起所述预写锁申请请求;
在S702中,若已确定所述数据编辑操作的元素地址,则通过所述第一进程发起写锁申请请求。
在本实施例中,第一进程可以根据是否确定元素地址,来判断是直接发起写锁申请请求,或是预写锁申请请求。由于确定元素地址需要一定的寻址时间,在寻址过程中无需申请独占写锁,而是申请预写锁即可,能够提高数据读共享的能力。
图8示出了本申请第六实施例提供的一种数据读写的控制方法的具体实现流程图。参见图8,相对于图1~6任一项所述实施例,本实施例提供的一种数据读写的控制方法还包括: S801~S803,具体详述如下:
进一步地,所述目标数据为B+树索引;所述数据编辑操作为对所述目标数据内的目标元素的删除操作;
在所述若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值之后,还包括:
在S801中,通过所述第一进程查询所述目标元素在所述B+树索引内位置信息;
在S802中,若在所述B+树索引内未查询到所述目标元素的所述位置信息,则通过所述第一进程释放申请的所述预写锁,并将所述预写标识位配置为所述第一位值;
在S803中若在所述B+树索引内查询到所述目标元素的所述位置信息,则通过所述第一进程发起所述写锁申请请求。
在本实施例中,上述数据编辑操作具体为对于B+树索引内的节点进行删除,在该情况下,上述实现过程具体可以包含以下步骤:
a)   第一进程可以向电子设备申请对B+树加预写锁,即预写锁申请请求。
b)   第一进程在接收到电子设备反馈的预写锁申请成功指令后(电子设备会将读写参量中预写标识pw置为1,此时写标识位为0),即开始对B+树进行检索,从根节点开始,查找要删除的元素所在的叶子节点和位置,即预写操作。
c)   第一进程如果查找失败,即元素不存在,则释放预写锁,流程终止,否则进入d)步骤。
d)第一进程若查找得到目标元素的位置信息,则向电子设备申请将预写锁转成独占写锁。
e)   第一进程申请写锁成功之后(锁的write置为1,此时pw为1,read为0),从相应叶子节点的位置上删除元素,并完成可能的节点合并操作。
f)   释放写锁(读写参量中的pw和write都置为0),删除元素流程完成。
与上述删除节点相比,则***元素的过程具体包含以下步骤:
a)第一进程首先向电子设备申请对B+树加预写锁;
b)第一进程在向电子设备申请预写锁成功之后(读写参量中的pw置为1,此时write为0),即开始对B+树进行检索,从根节点开始,查找新元素需要***的合适的叶子节点和位置,即执行预写操作;
c)第一进程找到叶子节点和位置后,即目标元素的位置信息,申请将预写锁转成独占写锁。
d)第一进程申请写锁成功之后(读写参量中的write置为1,此时pw为1,read为0),将元素写入相应节点及位置,并完成可能的节点***操作。
e)第一进程释放写锁(读写参量中的pw和write都置为0),***元素流程完成。
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
图9示出了本申请一实施例提供的一种数据读写的控制装置的结构框图,该数据读写的控制装置包括的各单元用于执行图1对应的实施例中的各步骤。具体请参阅图1与图1所对应的实施例中的相关描述。为了便于说明,仅示出了与本实施例相关的部分。
参见图9,所述数据读写的控制装置包括:
预写锁申请单元91,用于响应于第一进程发起的对于目标数据的预写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含预写标识位以及写标识位;
预写触发单元92,用于若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值,以使所述第一进程基于申请的预写锁执行预写操作;在所述预写标识位处于所述第二位值时,阻塞除所述第一进程外的其他进程发起的预写锁申请请求以及写锁申请请求;
写锁申请单元93,用于响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作;所述写锁申请请求是在所述第一进程执行完成所述预写操作后发起的。
可选地,所述预写触发单元92包括:
写锁申请请求响应单元,用于响应于所述写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含读标识位;
同意写锁执行单元,用于若所述读标识位为所述第三位值,则向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值,以使所述第一进程基于申请的写锁执行数据编辑操作;在所述写标识位处于所述第二位值时,阻塞应答其他进程发起预写锁申请请求、写锁申请请求以及读锁申请请求。
可选地,所述控制装置还包括:
读操作等待单元,用于若所述读标识位为除所述第三位值外的其他位值,则基于所述读标识位确定当前执行读取操作的进程个数;
读操作等待完成单元,用于响应于执行读取操作的其他进程反馈的读锁释放指令,调整所述读标识位的位值,直到调整后的读标识位为所述第三位值时,则执行所述向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值。
可选地,所述控制装置还包括:
读锁申请单元,用于响应于第二进程发起的对于所述目标数据的读锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位;
读锁申请同意单元,用于若所述写标识位为所述第一位值,则向所述第二进程反馈读同意指令,并增加所述读标识位,以使所述第二进程基于申请的读锁执行读取操作。
可选地,所述控制装置还包括:
写锁申请单元,用于响应于第三进程发起的对于所述目标数据的写锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位;
写锁申请同意单元,用于若所述预写标识位以及写标识位为第一位值,且所述读标识位为第三位值,则向所述第三进程反馈写同意指令,并将所述写标识位设置为第二位值,以使所述第三进程对所述目标数据执行数据编辑操作。
可选地,所述控制装置还包括:
元素地址待定单元,用于若未确定所述数据编辑操作的元素地址,则通过所述第一进程发起所述预写锁申请请求;
元素地址已知单元,用于若已确定所述数据编辑操作的元素地址,则通过所述第一进程发起写锁申请请求。
可选地,所述目标数据为B+树索引;所述数据编辑操作为对所述目标数据内的目标元素的删除操作;
所述控制装置还包括:
位置信息查询单元,用于通过所述第一进程查询所述目标元素在所述B+树索引内位置信息;
预写锁释放单元,用于若在所述B+树索引内未查询到所述目标元素的所述位置信息,则通过所述第一进程释放申请的所述预写锁,并将所述预写标识位配置为所述第一位值;
位置确认单元,用于若在所述B+树索引内查询到所述目标元素的所述位置信息,则通过所述第一进程发起所述写锁申请请求。
本申请的另一实施例还提供了一种数据读写的控制装置,用于根据读写参量分配预写锁、写锁以及读锁,其中,读写参量包括:预写标识位、写标识位以及读标识位;
在所述预写标识位为第一位值时,允许应答线程发起的预写申请请求,以向发起预写申请请求的进程分配预写锁,并在给任一进程分配预写锁后,将所述预写标识位设置为第二位值;
在所述预写标识位为第二位值时,阻塞应答线程发起的预写申请请求以及写申请请求,允许应答线程启发的读申请请求。
所述数据读写的控制装置还要用于:
在所述写标识以及所述预写锁均为第一位值时,允许应答线程发起的写申请请求,并在所述读标识位为第三位值时以向发起写申请请求的进程分配写锁,并在给任一进程分配写锁后,将所述写标识位设置为第二位值;
在所述写标识位为第二位值时,阻塞应答线程发起的预写申请请求、写申请请求以及读申请请求。
所述数据读写的控制装置还用于:
在所述读标识位为第三位值时,允许应答线程发起的写申请请求;
在所述写标识位为第一位值时,允许应答进程发起的读申请请求,并向发起读申请请求的进程分配读锁,并根据分配的读锁个数配置读标识位。
因此,本申请实施例提供的电子设备同样可以通过在读写参量中在写标识位的基础上,添加有对应的预写标识位,并在线程需要执行先进行寻址的写入操作时,可以发起一个预写锁申请请求,在检测到预写标识位处于第一位值时,向该线程反馈预写同意指令,即向该线程申请得到预写锁,可以执行预写操作;在预写操作过程中,该线程可以完成寻址任务,并允许其他进程读取目标数据,并在寻址完成后,该进程可以发起写锁申请请求,并基于执行后续的数据编辑操作,即对目标数据进行写入操作,实现了对同一目标数据的并发操作。与现有的数据读写的控制技术相比,本申请在对数据进行写入操作之前,假如了预写阶段,进程可以通过预写锁完成寻址操作,并且在预写阶段允许其他读取操作,从而能够在避免写入操作间相互冲突的同时,还能够减少寻址过程中对于数据的独占时长,大大提高了数据的共享读取能力。
图10是本申请另一实施例提供的一种电子设备的示意图。如图10所述,该实施例的电子设备10包括:处理器100、存储器101以及存储在所述存储器101中并可在所述处理器100上运行的计算机程序102,例如数据读写的控制程序。所述处理器100执行所述计算机程序102时实现上述各个数据读写的控制方法实施例中的步骤,例如图1所述的S101至S103。或者,所述处理器100执行所述计算机程序102时实现上述各装置实施例中各单元的功能,例如图9所述模块91至93功能。
示例性的,所述计算机程序102可以被分割成一个或多个单元,所述一个或者多个单元被存储在所述存储器101中,并由所述处理器100执行,以完成本申请。所述一个或多个单元可以是能够完成特定功能的一系列计算机程序指令段,该指令段用于描述所述计算机程序102在所述电子设备10中的执行过程。
所述电子设备可包括,但不仅限于,处理器100、存储器101。本领域技术人员可以理解,图10仅仅是电子设备10的示例,并不构成对电子设备10的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如所述电子设备还可以包括输入输出设备、网络接入设备、总线等。
所称处理器100可以是中央处理单元(Central Processing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
所述存储器101可以是所述电子设备10的内部存储单元,例如电子设备10的硬盘或内存。所述存储器101也可以是所述电子设备10的外部存储设备,例如所述电子设备10上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital, SD)卡,闪存卡(Flash Card)等。进一步地,所述存储器101还可以既包括所述电子设备10的内部存储单元也包括外部存储设备。所述存储器101用于存储所述计算机程序以及所述电子设备所需的其他程序和数据。所述存储器101还可以用于暂时地存储已经输出或者将要输出的数据。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。

Claims (10)

  1. 一种数据读写的控制方法,其特征在于,包括:
    响应于第一进程发起的对于目标数据的预写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含预写标识位以及写标识位;
    若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值,以使所述第一进程基于申请的预写锁执行预写操作;在所述预写标识位处于所述第二位值时,阻塞应答除所述第一进程外的其他进程发起的预写锁申请请求以及写锁申请请求,应答所述其他进程发起读锁申请请求;
    响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作;所述写锁申请请求是在所述第一进程执行完成所述预写操作后发起的。
  2. 根据权利要求1所述的控制方法,其特征在于,所述响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作,包括:
    响应于所述写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含读标识位;
    若所述读标识位为第三位值,则向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值,以使所述第一进程基于申请的写锁执行数据编辑操作;在所述写标识位处于所述第二位值时,阻塞应答其他进程发起预写锁申请请求、写锁申请请求以及读锁申请请求。
  3. 根据权利要求2所述的控制方法,其特征在于,在所述响应于所述写锁申请请求,确定所述目标数据的读写参量之后,还包括:
    若所述读标识位为除所述第三位值外的其他位值,则基于所述读标识位确定当前执行读取操作的进程个数;
    响应于执行读取操作的其他进程反馈的读锁释放指令,调整所述读标识位的位值,直到调整后的读标识位为所述第三位值时,则执行所述向所述第一进程反馈写入同意指令,并将所述写标识位为第二位值。
  4. 根据权利要求1所述的控制方法,其特征在于,还包括:
    响应于第二进程发起的对于所述目标数据的读锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位;
    若所述写标识位为所述第一位值,则向所述第二进程反馈读同意指令,并增加所述读标识位,以使所述第二进程基于申请的读锁执行读取操作。
  5. 根据权利要求1所述的控制方法,其特征在于,还包括:
    响应于第三进程发起的对于所述目标数据的写锁申请请求,确定所述目标数据的所述读写参量;所述读写参量还包含读标识位;
    若所述预写标识位以及写标识位为第一位值,且所述读标识位为第三位值,则向所述第三进程反馈写同意指令,并将所述写标识位设置为第二位值,以使所述第三进程对所述目标数据执行数据编辑操作。
  6. 根据权利要求1-5任一项所述的控制方法,其特征在于,在所述响应于第一进程发起的对于目标数据的预写锁申请请求之前,还包括:
    若未确定所述数据编辑操作的元素地址,则通过所述第一进程发起所述预写锁申请请求;
    若已确定所述数据编辑操作的元素地址,则通过所述第一进程发起写锁申请请求。
  7. 根据权利要求1-5任一项所述的控制方法,其特征在于,所述目标数据为B+树索引;所述数据编辑操作为对所述目标数据内的目标元素的删除操作;
    在所述若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值之后,还包括:
    通过所述第一进程查询所述目标元素在所述B+树索引内位置信息;
    若在所述B+树索引内未查询到所述目标元素的所述位置信息,则通过所述第一进程释放申请的所述预写锁,并将所述预写标识位配置为所述第一位值;
    若在所述B+树索引内查询到所述目标元素的所述位置信息,则通过所述第一进程发起所述写锁申请请求。
  8. 一种数据读写的控制装置,其特征在于,包括:
    预写锁申请单元,用于响应于第一进程发起的对于目标数据的预写锁申请请求,确定所述目标数据的读写参量;所述读写参量包含预写标识位以及写标识位;
    预写触发单元,用于若所述预写标识位为第一位值,则向所述第一进程反馈预写同意指令,并将所述预写标识位设置为第二位值,以使所述第一进程基于申请的预写锁执行预写操作;在所述预写标识位处于所述第二位值时,阻塞除所述第一进程外的其他进程发起的预写锁申请请求以及写锁申请请求;
    写锁申请单元,用于响应于所述第一进程发起的对于所述目标数据的写锁申请请求,向所述目标数据执行数据编辑操作;所述写锁申请请求是在所述第一进程执行完成所述预写操作后发起的。
  9. 一种电子设备,其特征在于,所述电子设备包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时如权利要求1至7任一项所述方法的步骤。
  10. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1至7任一项所述方法的步骤。
PCT/CN2022/125972 2021-12-31 2022-10-18 一种数据读写的控制方法及电子设备 WO2023124422A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111679116.9 2021-12-31
CN202111679116.9A CN114327642A (zh) 2021-12-31 2021-12-31 一种数据读写的控制方法及电子设备

Publications (1)

Publication Number Publication Date
WO2023124422A1 true WO2023124422A1 (zh) 2023-07-06

Family

ID=81022485

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/125972 WO2023124422A1 (zh) 2021-12-31 2022-10-18 一种数据读写的控制方法及电子设备

Country Status (2)

Country Link
CN (1) CN114327642A (zh)
WO (1) WO2023124422A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114327642A (zh) * 2021-12-31 2022-04-12 深圳市兆珑科技有限公司 一种数据读写的控制方法及电子设备
CN117407321B (zh) * 2023-12-13 2024-02-13 井芯微电子技术(天津)有限公司 一种芯片缓存的读写请求处理方法及相关装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6473849B1 (en) * 1999-09-17 2002-10-29 Advanced Micro Devices, Inc. Implementing locks in a distributed processing system
CN111880940A (zh) * 2020-07-29 2020-11-03 北京浪潮数据技术有限公司 一种存储***中数据处理方法、装置、设备及存储介质
CN112416556A (zh) * 2020-11-23 2021-02-26 西安西热电站信息技术有限公司 一种数据读写优先平衡方法、***、装置及存储介质
CN114327642A (zh) * 2021-12-31 2022-04-12 深圳市兆珑科技有限公司 一种数据读写的控制方法及电子设备

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6473849B1 (en) * 1999-09-17 2002-10-29 Advanced Micro Devices, Inc. Implementing locks in a distributed processing system
CN111880940A (zh) * 2020-07-29 2020-11-03 北京浪潮数据技术有限公司 一种存储***中数据处理方法、装置、设备及存储介质
CN112416556A (zh) * 2020-11-23 2021-02-26 西安西热电站信息技术有限公司 一种数据读写优先平衡方法、***、装置及存储介质
CN114327642A (zh) * 2021-12-31 2022-04-12 深圳市兆珑科技有限公司 一种数据读写的控制方法及电子设备

Also Published As

Publication number Publication date
CN114327642A (zh) 2022-04-12

Similar Documents

Publication Publication Date Title
CN112204513B (zh) 多租户存储***中的基于组的数据复制
US20220043829A1 (en) Methods for enhancing a legacy single tenant application system to a multi-tenant application system with minimal changes
WO2023124422A1 (zh) 一种数据读写的控制方法及电子设备
US9002802B2 (en) High throughput, reliable replication of transformed data in information systems
US7958091B2 (en) Method for fast bulk loading data into a database while bypassing exit routines
US10628200B2 (en) Base state for thin-provisioned volumes
US11048669B2 (en) Replicated state management using journal-based registers
WO2009158405A2 (en) Granting least privilege access for computing processes
CA2798138A1 (en) Sharing and synchronization of objects
WO2023231345A1 (zh) 对多个交易进行分组的方法和区块链节点
WO2022095366A1 (zh) 基于Redis的数据读取方法、装置、设备及可读存储介质
WO2016119597A1 (zh) Oltp集群数据库中页面查询方法及数据处理节点
WO2014153940A1 (zh) 处理数据库重做数据的方法和装置
US9183065B1 (en) Providing access to an application programming interface through a named pipe
US11500693B2 (en) Distributed system for distributed lock management and method for operating the same
CN112867999A (zh) 基于版本的表锁定
US9760577B2 (en) Write-behind caching in distributed file systems
CN109710698B (zh) 一种数据汇聚方法、装置、电子设备及介质
CN108920092B (zh) 内存数据的数据操作方法、装置及电子设备
CN112241398A (zh) 一种数据迁移方法和***
US9659041B2 (en) Model for capturing audit trail data with reduced probability of loss of critical data
WO2021159608A1 (zh) 一种基于Protocol Buffer的镜像缓存方法
WO2023056687A1 (zh) 一种固态硬盘及其数据操作方法、装置及电子设备
US10776344B2 (en) Index management in a multi-process environment
US11249656B2 (en) Performance optimization for active-active locking using sticking affinity for storage objects

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22913686

Country of ref document: EP

Kind code of ref document: A1