WO2023029937A1 - 数据处理方法、数据处理装置以及相关设备 - Google Patents

数据处理方法、数据处理装置以及相关设备 Download PDF

Info

Publication number
WO2023029937A1
WO2023029937A1 PCT/CN2022/111739 CN2022111739W WO2023029937A1 WO 2023029937 A1 WO2023029937 A1 WO 2023029937A1 CN 2022111739 W CN2022111739 W CN 2022111739W WO 2023029937 A1 WO2023029937 A1 WO 2023029937A1
Authority
WO
WIPO (PCT)
Prior art keywords
storage area
area
read
pointer
write
Prior art date
Application number
PCT/CN2022/111739
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 华为技术有限公司
Priority to EP22863077.8A priority Critical patent/EP4386539A1/en
Publication of WO2023029937A1 publication Critical patent/WO2023029937A1/zh
Priority to US18/589,722 priority patent/US20240201907A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F5/00Methods or arrangements for data conversion without changing the order or content of the data handled
    • G06F5/06Methods or arrangements for data conversion without changing the order or content of the data handled for changing the speed of data flow, i.e. speed regularising or timing, e.g. delay lines, FIFO buffers; over- or underrun control therefor
    • G06F5/10Methods or arrangements for data conversion without changing the order or content of the data handled for changing the speed of data flow, i.e. speed regularising or timing, e.g. delay lines, FIFO buffers; over- or underrun control therefor having a sequence of storage locations each being individually accessible for both enqueue and dequeue operations, e.g. using random access memory
    • G06F5/12Means for monitoring the fill level; Means for resolving contention, i.e. conflicts between simultaneous enqueue and dequeue operations
    • 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
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0655Vertical data movement, i.e. input-output transfer; data movement between one or more hosts and one or more storage devices
    • G06F3/0659Command handling arrangements, e.g. command buffers, queues, command scheduling
    • 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
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0604Improving or facilitating administration, e.g. storage management
    • 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
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0644Management of space entities, e.g. partitions, extents, pools
    • 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
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device

Definitions

  • the present application relates to the field of computers, in particular to a data processing method, a data processing device and related equipment.
  • the circular storage queue is a special first-in first-out queue.
  • the circular storage queue connects the last location in the storage space to the first location to form a logical circular space.
  • FIG. 1 is a schematic structural diagram of a circular storage queue.
  • the circular storage queue includes corresponding global write pointers and global read pointers.
  • the area between the global write pointer and the global read pointer is storage area b.
  • the area between the global read pointer and the global write pointer is area a.
  • the data in area a is about to be read, and the data in area b is about to be written.
  • the global write pointer and global read pointer move counterclockwise. For example, after thread 1 is allocated to sub-area b1, the global write pointer moves to sub-area b2. After thread 2 is allocated to the sub-area b2, the global write pointer moves to the remaining area b3.
  • threads After writing data, different threads perform sequential commits. Specifically, after writing data in sub-area b1, thread 1 executes a commit operation. The commit operation indicates that data has been written in the sub-area b1. Data in the sub-area b1 can be read. Similarly, after writing data in sub-area b2, thread 2 executes the commit operation. The commit operation indicates that data has been written in the sub-area b2. Data in the sub-area b2 can be read. If different threads execute out-of-order commits, the reading of data will be affected. Specifically, if thread 2 performs a commit operation in advance, after the global read pointer moves to sub-area b1, there may be threads reading data in sub-area b1. However, thread 1 has not finished writing the data. Therefore, the data read by the thread may be wrong.
  • thread 2 After thread 2 writes data first, thread 2 will enter the waiting state until thread 1 completes the commit operation. During the waiting period, thread 2 needs to frequently judge whether thread 1 has completed the commit operation, thereby reducing the operating efficiency of the system.
  • the present application provides a data processing method, a data processing device and related equipment.
  • the out-of-order commit will not affect the correctness of the read data. Therefore, this application can improve the operating efficiency of the system through out-of-order commit.
  • the first aspect of the present application provides a data processing method.
  • the data processing method can be applied in an operating system including circular store queues.
  • the execution subject of the data processing method may be a thread, an operating system, or a computer device installed with an operating system.
  • the data processing method will be described by taking the execution subject as a computer device as an example.
  • the data processing method includes the following steps: the computer device acquires the first global read pointer of the circular storage queue.
  • the circular storage queue includes M storage areas. M is an integer greater than 1. Each memory area is logically contiguous.
  • the first global read pointer points to the first storage area in the M storage areas.
  • the computer device acquires the first write identifier of the first storage area. Each storage area in the M storage areas corresponds to a write flag.
  • the first storage area corresponds to the first write mark.
  • the first write mark represents the space size of the stored data in the first storage area.
  • the computer device determines the size of the allocated space in the first storage area. Through the first write flag, the computer device can determine the commit state of the first storage area.
  • the commit status includes full commit and incomplete commit.
  • a full commit means that the space size of the stored data in the first storage area is equal to the size of the allocated space in the first storage area.
  • Incomplete commit means that the space size of the stored data in the first storage area is smaller than the allocated space size in the first storage area.
  • the computer device reads the first data in the first sub-area.
  • the first condition includes: the commit state of the first storage area is a complete commit.
  • the first write mark represents the data size. Therefore, in the first storage area, the out-of-order commit will not affect the judgment of the commit state, that is, the out-of-order commit will not affect the correctness of the read data. Therefore, after writing data in the first storage area, the thread does not need to wait for other threads to complete the commit operation, thereby improving the operating efficiency of the system.
  • the computer device determines that the allocated space in the first storage area is equal to the total size of the first storage area size of space. And/or, if the first global write pointer points to the first storage area, the computer device determines the size of the allocated space in the first storage area or is equal to the difference between the position of the first byte and the starting position of the first storage area value.
  • the first global write pointer points to the first byte in the first storage area.
  • the allocated space size in the first storage area may also be recorded through an additional identification.
  • the size of the allocated space in the first storage area is determined by the first global write pointer, which can improve the utilization rate of the first global write pointer and save the storage space of the system.
  • the data processing method before reading the first data in the first subarea, further includes: the computer device acquires a first read identifier of the first storage area.
  • the first read flag represents the data size of the read data in the first storage area.
  • the computer device determines the size relationship between the first write mark and the first read mark.
  • the first condition further includes: the first write mark is greater than the first read mark.
  • the sizes of the first sub-area and the first data are X bytes. X is an integer greater than 0.
  • the data processing method further includes: the computer device updates the first read flag of the first storage area through X.
  • the updated first read identifier is equal to the sum of the first read identifier and X.
  • the data processing method further includes: the computer device acquires the second global write pointer of the circular storage queue.
  • the second global write pointer points to the second byte in the first storage area.
  • the starting position of the first sub-area is the second byte. If the difference between the position of the second byte and the end position of the first storage area is greater than or equal to X, the computer device writes the first data from the second byte. If the difference between the position of the second byte and the end position of the first storage area is less than X, the computer device does not start writing the first data at the second byte. Wherein, a difference value smaller than X indicates that the remaining space of the first storage area is insufficient.
  • the current thread can only write part of the first data in the remaining space.
  • the current thread also needs to write another part of the first data in the first sub-area of the next storage area.
  • the current thread may not be allocated to the first sub-area of the next storage area.
  • another part of the first data cannot be written into the first sub-area, thereby reducing the reliability of the system.
  • a difference greater than or equal to X indicates that the first storage area has enough free space.
  • the computer device writes the first data in the remaining space only when there is enough remaining space. Therefore, the present application can improve the reliability of the system.
  • the data processing method further includes: the computer device acquires a third global write pointer of the circular storage queue.
  • the third global write pointer points to the third byte of the first storage area.
  • the computer device acquires the size of the second data to be written.
  • the size of the second data is N bytes. If the position of the third byte and the end position of the first storage area indicate that the remaining area of the first storage area is less than N bytes, then the computer device adds a target identifier to the remaining area.
  • the target flag is used to characterize the remaining area as an invalid sub-area.
  • the computer device can add a target logo to the head of the remaining area. By adding the target identifier, it is possible to prevent the computer device from reading wrong data. For example, bad data could be data written in a previous cycle that has already been read. Therefore, the present application can improve the reliability of the system.
  • the data processing method before reading the first data in the first subarea, further includes: the computer device determines whether the first subarea is an invalid subarea.
  • the first condition further includes: the first sub-area is not an invalid sub-area. If the first sub-area is an invalid sub-area, the computer device does not read the data in the first sub-area. Wherein, if the computer device reads invalid data in the first sub-area, system resources will be wasted.
  • the present application can avoid wasting system resources by determining whether the first sub-area is an invalid sub-area before reading the first data.
  • the data processing method further includes: if the second condition is satisfied, the computer device updates the third global write pointer.
  • the updated third global write pointer points to the second storage area.
  • the second storage area is the next storage area of the first storage area.
  • the second condition includes: the second storage area has not been allocated. Or the third global read pointer points to a storage area other than the second storage area.
  • the second write mark of the second storage area divided by the total space size of the second storage area is equal to an integer.
  • the second write mark represents the space size of the stored data in the second storage area.
  • the third global read pointer points to a storage area other than the second storage area
  • the second write mark of the second storage area divided by the total space size of the second storage area is equal to an integer
  • the third global read pointer points to the second storage area, or the second write mark of the second storage area divided by the total space size of the second storage area is not equal to an integer, it means that in the last cycle, the second storage area The data of is not completely written.
  • the computer device cannot update the third global write pointer. Otherwise, two threads may write data to the same byte at the same time, causing system exceptions.
  • the stability of the system can be improved.
  • the data processing method before the computer device updates the third global write pointer, the data processing method further includes: the computer device clears the second write flag.
  • the first global read pointer includes a first read area pointer and a read offset pointer within the first area.
  • the first read area pointer points to the first storage area.
  • the read offset pointer in the first area points to the second byte in the first storage area.
  • the first global write pointer includes a first write area pointer and a write offset pointer within the first area.
  • the data processing method further includes: if the difference between the first read area pointer and the first write area pointer is greater than M, then the computer device clears the first read flag .
  • the computer device in order to improve the efficiency of data writing, when the computer device writes data, it may overwrite unread data.
  • the first write flag is equal to the first read flag, the data in the first sub-area may not be read. Therefore, if the computer device still determines whether to execute the judgment of the commit state through the size relationship of the first read mark of the first write mark, it may cause a system abnormality, for example, the data cannot be read. Therefore, this application can improve the reliability of the system by clearing.
  • the data processing method further includes: if the difference between the first read area pointer and the first write area pointer is greater than M, updating the first read area pointer.
  • the amount of lost data can be reduced as much as possible and the reliability of the system can be improved.
  • the second condition further includes: dividing the second read flag of the second storage area by the total space size of the second storage area is equal to an integer.
  • the second read flag represents the data size of the read data in the second storage area. Wherein, when the second read flag divided by the total space size of the second storage area is equal to an integer, it means that in the last cycle, the data in the second storage area has been completely read. When the second read flag divided by the total space size of the second storage area is not equal to an integer, it means that the data in the second storage area has not been completely read in the last cycle.
  • the second aspect of the present application provides a data processing device.
  • the data processing device includes a first acquisition module, a second acquisition module, a processing module and a reading module.
  • the first obtaining module is used to obtain the first global read pointer of the circular storage queue.
  • the circular storage queue includes M storage areas. M is an integer greater than 1.
  • the first global read pointer points to the first storage area in the M storage areas.
  • the second obtaining module is used to obtain the first write mark of the first storage area.
  • the first write mark represents the space size of the data stored in the first storage area.
  • the processing module is used to determine the size of the allocated space in the first storage area.
  • the reading module is used for reading the first data in the first sub-area if the first condition is satisfied.
  • the first condition includes: the space size of the stored data in the first storage area is equal to the allocated space size in the first storage area.
  • the processing module is configured to determine that the allocated space in the first storage area is equal to the first storage area if the first global write pointer points to a storage area other than the first storage area total space size. And/or, the processing module is configured to, if the first global write pointer points to the first storage area, determine that the size of the allocated space in the first storage area is equal to the position of the first byte and the starting position of the first storage area difference. The first global write pointer points to the first byte in the first storage area.
  • the first acquiring module is further configured to acquire a first read identifier of the first storage area.
  • the first read flag represents the data size of the read data in the first storage area.
  • the processing module is also used to determine the size relationship between the first write marker and the first read marker; the first condition further includes: the first write marker is larger than the first read marker.
  • the data processing device further includes an update module.
  • the size of the first sub-area and the first data is X bytes. X is an integer greater than 0.
  • the update module is used to update the first read flag of the first storage area through X.
  • the updated first read identifier is equal to the sum of the first read identifier and X.
  • the first acquiring module is further configured to acquire a second global write pointer of the circular storage queue.
  • the second global write pointer points to the second byte in the first storage area.
  • the starting position of the first storage area is the second byte.
  • the data processing device also includes a writing module. The writing module is used for writing the first data in the first sub-area if the difference between the position of the second byte and the end position of the first storage area is greater than or equal to X.
  • the first acquiring module is further configured to acquire a third global write pointer of the circular storage queue.
  • the third global write pointer points to the third byte of the first storage area.
  • the first obtaining module is also used to obtain the size of the second data to be written.
  • the size of the second data is N bytes.
  • the data processing device also includes an add-on module.
  • the adding module is used for adding a target identifier to the remaining area if the position of the third byte and the end position of the first storage area indicate that the remaining area of the first storage area is less than N bytes.
  • the target flag is used to characterize the remaining area as an invalid sub-area.
  • the processing module is further configured to determine whether the first subregion is an invalid subregion.
  • the first condition further includes: the first sub-area is not an invalid sub-area.
  • the data processing device further includes an update module.
  • the update module is used to update the third global write pointer if the second condition is satisfied.
  • the updated third global write pointer points to the first byte of the second storage area.
  • the second storage area is the next storage area of the first storage area.
  • the second condition includes: the second storage area has not been allocated, or the third global read pointer points to a storage area other than the second storage area.
  • the second write mark of the second storage area divided by the total space size of the second storage area is equal to an integer.
  • the second write mark represents the space size of the stored data in the second storage area.
  • the data processing device further includes a clearing module.
  • the clearing module is used for clearing the second write flag.
  • the first global read pointer includes a first read area pointer and a read offset pointer within the first area.
  • the first read area pointer points to the first storage area.
  • the read offset pointer in the first area points to the second byte in the first storage area.
  • the first global write pointer includes a first write area pointer and a write offset pointer within the first area.
  • the clearing module is further configured to clear the first read flag in the first storage area if the difference between the first read area pointer and the first write area pointer is greater than M.
  • the update module is further configured to update the first read area pointer if the difference between the first read area pointer and the first write area pointer is greater than M.
  • the second condition further includes: dividing the second read flag of the second storage area by the total space size of the second storage area is equal to an integer.
  • the second read flag represents the data size of the read data in the second storage area.
  • a computer device includes memory and a processor.
  • a first global read pointer of the circular storage queue is stored in the memory.
  • the circular storage queue includes M storage areas. M is an integer greater than 1.
  • the first global read pointer points to the first storage area in the M storage areas.
  • the first write mark of the first storage area is also stored in the memory.
  • the first write mark represents the space size of the stored data in the first storage area.
  • the processor is configured to determine the size of the allocated space in the first storage area.
  • the processor is configured to read the first data in the first sub-area if the first condition is satisfied.
  • the first condition includes: the space size of the stored data in the first storage area is equal to the allocated space size in the first storage area.
  • the processor is configured to determine that the allocated space in the first storage area is equal to the total size of the first storage area if the first global write pointer points to a storage area other than the first storage area. space size. And/or, the processor is configured to determine that the size of the allocated space in the first storage area is equal to the difference between the position of the first byte and the starting position of the first storage area if the first global write pointer points to the first storage area value. The first global write pointer points to the first byte of the first storage area.
  • the processor is further configured to obtain a first read identifier of the first storage area.
  • the first read flag represents the space size of the read data in the first storage area.
  • the processor is further configured to determine a size relationship between the first write mark and the first read mark; the first condition further includes: the first write mark is greater than the first read mark.
  • the sizes of the first sub-area and the first data are X bytes.
  • X is an integer greater than 0.
  • the processor is further configured to use X to update the first read flag of the first storage area.
  • the updated first read identifier is equal to the sum of the first read identifier and X.
  • the processor is further configured to obtain a second global write pointer of the circular storage queue.
  • the second global write pointer points to the second byte in the first storage area.
  • the second byte is the start position of the first sub-area.
  • the processor is further configured to write the first data in the first sub-area if the difference between the position of the second byte and the end position of the first storage area is greater than or equal to X.
  • the processor is further configured to acquire a third global write pointer of the circular storage queue.
  • the third global write pointer points to the third byte of the first storage area.
  • the processor is also used to acquire the size of the second data to be written.
  • the size of the second data is N bytes.
  • the processor is further configured to add a target identifier to the remaining area if the position of the third byte and the end position of the first storage area indicate that the remaining area of the first storage area is less than N bytes.
  • the target flag is used to characterize the remaining area as an invalid sub-area.
  • the processor is further configured to determine whether the first subregion is an invalid subregion.
  • the first condition further includes: the first sub-area is not an invalid sub-area.
  • the processor is further configured to update the third global write pointer if the second condition is met.
  • the updated third global write pointer points to the first byte of the second storage area.
  • the second storage area is the next storage area of the first storage area.
  • the second condition includes: the second storage area has not been allocated, or the third global read pointer points to a storage area other than the second storage area.
  • the second write mark of the second storage area divided by the total space size of the second storage area is equal to an integer.
  • the second write mark represents the space size of the stored data in the second storage area.
  • the processor is further configured to clear the second write flag.
  • the first global read pointer includes a first read area pointer and a read offset pointer within the first area.
  • the first read area pointer points to the first storage area.
  • the read offset pointer in the first area points to the second byte in the first storage area.
  • the first global write pointer includes a first write area pointer and a write offset pointer within the first area.
  • the processor is further configured to clear the first read flag in the first storage area if the difference between the first read area pointer and the first write area pointer is greater than M.
  • the processor is further configured to update the first read area pointer if the difference between the first read area pointer and the first write area pointer is greater than M.
  • the second condition further includes: dividing the second read flag of the second storage area by the total space size of the second storage area is equal to an integer.
  • the second read flag represents the data size of the read data in the second storage area.
  • the fourth aspect of the present application provides a computer storage medium, which is characterized in that instructions are stored in the computer storage medium, and when the instructions are executed on a computer device, the computer device executes the computer device according to the first aspect or the first method.
  • the fifth aspect of the present application provides a computer program product, which is characterized in that, when the computer program product is executed on a computer device, the computer device executes the computer program described in the first aspect or any one of the implementation manners of the first aspect. Methods.
  • Fig. 1 is a structural schematic diagram of a circular storage queue
  • Fig. 2 is a schematic flow chart of the data processing method provided in this application.
  • Fig. 3 is the first schematic structural diagram of the circular storage queue provided in the present application.
  • Fig. 4 is the first schematic flow chart of the method for writing data provided in this application.
  • FIG. 5 is a second structural schematic diagram of the circular storage queue provided in the present application.
  • FIG. 6 is a schematic structural diagram of the global write pointer provided in this application.
  • Fig. 7 is the first schematic flow chart of the method for reading data provided in this application.
  • FIG. 8 is a second schematic flowchart of the method for writing data provided in this application.
  • FIG. 9 is a second schematic flowchart of the method for reading data provided in this application.
  • FIG. 10 is a schematic structural diagram of a data processing device provided in this application.
  • FIG. 11 is a schematic structural diagram of a computer device provided in this application.
  • the present application provides a data processing method, a data processing device and related equipment.
  • the out-of-order commit will not affect the correctness of the read data. Therefore, this application can improve the operating efficiency of the system through out-of-order commit.
  • first”, “second”, “target” and the like used in this application are only used for the purpose of distinguishing and describing, and cannot be interpreted as indicating or implying relative importance, nor indicating or implying order.
  • reference numerals and/or letters are repeated in the various figures of this application for the sake of brevity and clarity. Repetition does not imply a strictly limited relationship between the various embodiments and/or configurations.
  • the data processing method in the present application can be applied in the computer field, such as an operating system using a circular storage queue.
  • different threads must perform commit operations in a specific order, referred to as sequential commit.
  • the specific order refers to the direction of movement of the global write pointer and the global read pointer.
  • the particular order is counterclockwise.
  • Fig. 2 is a schematic flow chart of the first data processing method provided in this application. As shown in Figure 2, the data processing method includes the following steps.
  • a computer device acquires a first global read pointer of a circular storage queue.
  • the first global read pointer points to the first sub-area in the first storage area.
  • the data processing method in this application adopts another circular storage queue.
  • the circular storage queue is divided into logically M storage areas.
  • M is an integer greater than 1.
  • Each storage area is logically contiguous.
  • Each storage area corresponds to a write flag.
  • the write flag represents the data size of the data stored in the corresponding storage area.
  • FIG. 3 is a first structural schematic diagram of the circular storage queue provided in this application.
  • the circular storage queue includes three storage areas.
  • the space sizes of the three storage areas can be the same or different.
  • the three storage areas are respectively a storage area 301 , a storage area 302 and a storage area 303 .
  • Three storage areas correspond to three write flags. There is a one-to-one correspondence between the three storage areas and the three write marks.
  • the circular storage queue also includes corresponding global write pointers and global read pointers.
  • the positions of the global write pointer and the global read pointer are constantly changing along the logical direction.
  • the logical direction is counterclockwise. It should be understood that in practical applications, the logical direction may also be clockwise.
  • a circular storage queue is a logical ring space. therefore.
  • a global write pointer or a global read pointer can cycle through the same area. According to the foregoing description, it can be seen that in the time domain, the positions of the global write pointer and the global read pointer may change continuously. Therefore, for the convenience of description, in this application, the global write pointer and the global read pointer at different times may have different names. For example, different titles include first global write pointer, first global read pointer, second global write pointer, second global read pointer, and so on.
  • a computer device obtains a first global read pointer of a circular storage queue.
  • the first global read pointer points to the first sub-area in the first storage area.
  • the first global read pointer may point to the start position of the first sub-area.
  • the starting position may be the first byte of the first sub-area.
  • the first storage area is one of the M storage areas.
  • the computer device writes data in units of sub-areas. For example, the total space size of the storage area 301 is 100 bytes.
  • the computer device allocated the first 40 bytes to thread 1.
  • the computer device allocated the last 60 bytes to thread 2.
  • Thread 1 writes data in the first 40 bytes.
  • Thread 2 writes data in the last 60 bytes.
  • Each storage area can include one or more sub-areas.
  • the first sub-area is any one of the one or more sub-areas.
  • step 202 the computer device acquires a first write identifier of the first storage area.
  • each storage area corresponds to a write flag.
  • the first storage area corresponds to the first write mark.
  • the first write mark represents the space size of the stored data in the first storage area. It should be understood that in this application, the space size of the stored data in the first storage area only includes the data size of the data written by the computer device in the last cycle.
  • the computer device cyclically allocates storage space in the first storage area. For example, in the first loop, the computer device allocates the first memory area to thread 1 and thread 2 . In the second loop, the computer device allocates the first memory area to thread 1 , thread 3 and thread 4 . In a last loop, the computer device allocates the first memory area to one or more threads.
  • the first write flag is used to represent the data size of the data written in the first storage area by one or more threads in the last cycle. Wherein, the value of the first write flag changes with the commit operation of the thread.
  • the first storage area includes a first sub-area and a second sub-area.
  • the first sub-area includes 40 bytes.
  • the second sub-area includes 60 bytes.
  • the value of the first write flag may be a multiple of 0 or 100. Assume that the value of the first write flag is 0.
  • thread 1 writes data in the first sub-area
  • thread 1 performs a commit operation.
  • the first write flag becomes 40.
  • thread 1 writes data in the second sub-area
  • thread 2 executes the commit operation.
  • the second write flag becomes 100.
  • step 203 if the space size of the stored data in the first storage area represented by the first write mark is equal to the allocated space size in the first storage area, the computer device reads the first data in the first sub-area .
  • the computer device can determine the commit state of the first storage area.
  • the commit status includes full commit and incomplete commit.
  • a full commit means that the space size of the stored data in the first storage area is equal to the size of the allocated space.
  • Incomplete commit means that the space size of the stored data in the first storage area is smaller than the allocated space size.
  • the first write mark represents the space size of the stored data. If the space size of the stored data is equal to the size of the allocated space, the computer device reads the first data in the first sub-area. The size of the first sub-area and the first data is X bytes. X is an integer greater than 0. If the space size of the stored data is smaller than the allocated space size, the computer device does not read the data in the first sub-area. For example, assume that the size of the allocated space in the first storage area is 100 bytes. Among them, thread 1 allocated the first 40 bytes. Thread 2 is allocated the last 60 bytes. The first sub-area is the first 40 bytes. After thread 2 executes the commit operation, the last 60 bytes become the space for stored data.
  • the size of the allocated space is not equal to the size of the stored data.
  • the computer device does not read the data in the first sub-area. After thread 1 executes the commit operation, the first 40 bytes become the space for stored data. At this point, the size of the allocated space is 100 bytes. The size of the allocated space is equal to the size of the stored data.
  • the computer device reads data in the first sub-area. Therefore, in the first storage area, the out-of-order commit will not affect the judgment of the commit state, that is, the out-of-order commit will not affect the correctness of the read data. Therefore, after thread 2 writes data in the first storage area, thread 2 does not need to wait for thread 1 to complete the commit operation, thereby improving the operating efficiency of the system.
  • the computer device may determine the size of the allocated space in the first storage area through the first global write pointer. Specifically, if the first global write pointer points to a storage area other than the first storage area, the computer device determines that the allocated space in the first storage area is equal to the total space size of the first storage area. If the first global write pointer points to the second sub-area in the first storage area, the computer device determines that the size of the allocated space in the first storage area is equal to the start position of the second sub-area and the start of the first storage area difference in position. For example, the first storage area includes 200 bytes. The start position of the second sub-area is the 101st byte among the 200 bytes. At this point, the computer device determines that the size of the allocated space is 100 bytes.
  • each storage area in the circular storage queue corresponds to a write flag.
  • the write flag is used to represent the space size of the stored data in the corresponding storage area.
  • each storage area may also correspond to a read identifier.
  • the read flag is used to represent the data size of the data that has been read in the corresponding storage area.
  • the first read flag is used to represent the data size of the read data in the first storage area.
  • the computer device may determine the size relationship between the first write mark and the first read mark.
  • the first write flag is equal to the first read flag
  • the data size representing the read data in the first storage area is equal to the space size of the stored data. At this point, no data has been written into the first sub-area. Therefore, the computer device does not need to perform step 203 .
  • the first write flag is smaller than the first read flag
  • the data size representing the read data in the first storage area is smaller than the space size of the stored data, and at this time, the data has been written in the first sub-area. Therefore, the computer device executes step 203 .
  • the first read flag is used to represent the data size of the read data in the first storage area. Therefore, after reading the data in the first sub-area, the computer device can update the first read flag.
  • the updated first read identifier is equal to the sum of the first read identifier and X.
  • X is the data size of the first data. Or X is the space size of the first sub-region.
  • computer devices write and read data in subregions.
  • the computer device reads the first data in the first sub-area. Therefore, before the computer device reads the first data, the computer device also writes the first data in the first sub-area. Specifically, the computer device obtains the second global write pointer of the circular storage queue. The second global write pointer points to the second byte in the first storage area. Wherein, the second byte is the starting position of the first sub-area. It should be understood that when writing data, the computer device can flexibly adjust the space size of the sub-region according to the data size of the first data. Therefore, in different cycles, the number and space size of sub-regions in each storage region may be different.
  • the computer device starts writing the first data from the second byte. If the difference between the position of the second byte and the end position of the first storage area is less than X, it indicates that the remaining space in the first storage area is smaller than the data size of the first data. The computer device cannot write the first data in the remaining space.
  • FIG. 4 is a first schematic flowchart of the method for writing data provided in this application.
  • the data processing method in the present application can be applied to writing and reading data in the circular storage queue.
  • the present application divides the data processing method into a method of writing data and a method of reading data. There is a certain correlation between the method of writing data and the method of reading data. Therefore, the descriptions in the two methods can refer to each other.
  • the method for writing data includes the following steps.
  • the computer device obtains the current global write pointer, and determines the current storage area according to the current global write pointer.
  • the computing device obtains the current global write pointer of the circular storage queue.
  • the current global write pointer is also referred to as the current global write pointer.
  • the current global write pointer points to the current storage area among the M storage areas.
  • the computer device can obtain the current global write pointer from the queue head of the circular storage queue.
  • FIG. 5 is a second structural schematic diagram of the circular storage queue provided in this application. As shown in Figure 5, the circular storage queue includes 3 storage areas.
  • the three storage areas are respectively a storage area 301 , a storage area 302 and a storage area 303 .
  • the storage area 301 includes a sub-area a1 , a sub-area b1 , a sub-area b2 , and a target invalidation sub-area 502 .
  • the storage area 302 includes a sub-area b4, a sub-area b5, and a remaining space a2. Among them, the remaining space a2 may be assigned one or more threads by the computer device. Therefore, the remaining space a2 may form a plurality of sub-regions.
  • the storage area 303 includes a subarea a3 , a4 , and a target invalidation subarea 504 .
  • the circular storage queue also includes a queue head 500 .
  • the queue head 500 can be used to store global write pointers and global read pointers.
  • the global write pointer points to the sub-area a2 in the storage area 302 .
  • the global read pointer points to the sub-area b1 in the storage area 301 .
  • Each memory region may also include a corresponding region header.
  • the area header is used to store the read flag and/or write flag of the corresponding storage area.
  • storage area 301 includes area header 501 .
  • the area header 501 is used to store a write flag and/or a read flag of the storage area 301 .
  • storage area 302 includes area header 503 .
  • the storage area 303 includes an area header 505 .
  • Each storage area may also include a corresponding initial invalid sub-area (not shown in the figure).
  • the global write pointer When the space of the storage area is fully allocated, the global write pointer will point to the initially invalid sub-area. When the space of the storage area is incompletely allocated, the remaining area of the storage area of the computer device is merged with the initial invalid sub-area to obtain the invalid sub-area.
  • storage area 301 includes 100 bytes.
  • the initial invalid sub-area consists of 2 bytes. If the 100 bytes of the storage area 301 are fully allocated, the global write pointer will point to the initial invalid sub-area of the storage area 301 .
  • the computer device treats the initial invalid subregion as an invalid subregion.
  • the global write pointer When the space of the storage area 301 is incompletely allocated, the global write pointer will point to the remaining space of the storage area 301 . If the remaining space is smaller than the size of the data to be written, the computer device uses the remaining space as the target invalid sub-area. The computer device merges the target invalid sub-region and the initial invalid sub-region to obtain the invalid sub-region. For example, if 100 bytes of the storage area 301 are incompletely allocated, the remaining space includes 10 bytes. If the remaining space of 10 bytes is less than the data size of the current data (data to be written), then the computer device can use 10 bytes as the target invalid sub-area. The computer device merges the target invalid sub-region and the initial invalid sub-region to obtain the invalid sub-region. At this time, the invalid sub-area includes 12 bytes.
  • step 402 the computer device determines whether there is enough free space in the current storage area according to the current global write pointer and the current data size.
  • the current data size is the data size of the current data to be written by the current thread.
  • the current global write pointer points to the current byte in the current memory area. If the difference between the end position of the current storage area and the current byte is smaller than the current data size, it means that the current storage area does not have enough remaining space. If the difference between the end position of the current storage area and the current byte is greater than or equal to the data size of the current data, it indicates that the current storage area has enough remaining space. If there is enough free space, the computer device executes step 403 . If there is not enough free space, the computer device executes step 406 .
  • step 403 the computer device determines whether the head grabbing is successful. Among them, in a multi-thread concurrent scenario, multiple threads may compete to write data. Only after the current thread successfully grabs the head, the computer device can start writing the current data from the current byte. If the current thread succeeds in grabbing the head, the computer device executes step 404 . If the head grabbing is successful, it means that the computer device has updated the current global write pointer. The updated current global write pointer points to the last X bytes of the current byte. X current data size. Specifically, the computer device can update the current global write pointer through an atomic operation. For example, a computer device may update the current global write pointer through a compare and swap (CAS) technique.
  • CAS compare and swap
  • the computer device can update the global write pointer or the global read pointer through atomic operations. If the current thread fails to seize the head, the computer device executes step 401 . Among them, if the current thread fails to grab the head, other threads have already modified the current global write pointer. Therefore, the computer device needs to perform step 401 again.
  • step 404 the computer device executes the write process. After the header is successfully grabbed, the computer device starts to write the current data from the current byte.
  • the data size of the current data is X bytes.
  • step 405 the computer device updates the current write flag of the current storage space.
  • the current write flag corresponds to the current storage area.
  • the current write flag represents the data size of the data stored in the current storage area.
  • the computer device updates the current write flag.
  • the updated current write flag is equal to the sum of the current write flag plus X.
  • the computer device writes data in the current storage area cyclically. Therefore, the value of the current write flag can be continuously increased.
  • the computer device may also continuously clear the current writing flag. Specifically, when the value of the current write flag is equal to the total space size of the current storage area, the computer device clears the current write flag. For example, the total space size of the current storage area is 100 bytes. When the value of the current writing flag is equal to 100, the computer device sets the value of the current writing flag to 0.
  • step 406 the computer device determines whether the remaining space is an invalid sub-region.
  • the computer device can determine whether the remaining space is an invalid sub-area through the target identifier.
  • the target identifier is that the bits in the remaining space are all 1s. If the bits in the remaining space are all 1, the computer device determines that the remaining space is an invalid sub-area. If the bits in the remaining space are not all 1, the computer device determines that the remaining space is not an invalid sub-area.
  • the target ID is the ID in the header of the remaining space.
  • the computer device sets a corresponding header. After the computer device determines that there is not enough remaining space, the computer device uses the remaining space as the target invalid sub-area.
  • the computer device adds the target identification to the head of the target invalid sub-area.
  • the specific content of the target identifier can be the value of a certain bit. For example, when the value of the bit is 1, it indicates that the remaining space is an invalid sub-area. When the value of the bit is 0, it indicates that the remaining space is not an invalid sub-area. If the remaining space is not an invalid sub-area, go to step 407. If the remaining space is an invalid sub-area, go to step 408 .
  • the description of the invalid sub-region reference may be made to the description in the foregoing step 401 .
  • the current global write pointer may point to the initial invalid sub-area corresponding to the current storage area. At this time, there is not enough free space in the current storage area.
  • the computer device determines that the initial invalid sub-region is an invalid sub-region. The computer device executes step 408 .
  • step 407 the computer device takes the remaining space as an invalid sub-area. If the current storage area includes an initial invalid sub-area, the computer device combines the remaining space with the initial invalid sub-area to obtain an invalid sub-area. If the current storage area does not include the initial invalid sub-area, the computer device takes the remaining space as the invalid sub-area. If there is no target mark in the remaining space, the computer device adds a target mark to the remaining space. For the description about the target identification, refer to the description in the aforementioned step 406 .
  • step 408 the computer device calculates the global write pointer of the next storage area according to the current global write pointer.
  • the next storage area is the next storage area in the logical direction of the current storage area.
  • the computer device calculates the global write pointer of the next storage area according to the current global write pointer.
  • the global write pointer of the next storage area points to the next storage area.
  • the global write pointer of the next storage area points to the start position of the next storage area. It should be understood that at this time, the computer device does not modify the current global write pointer.
  • step 409 the computer device determines whether the next storage area has been allocated according to the global write pointer of the next storage area. Specifically, depending on the format of the global write pointer of the next storage area, the computer device may determine whether the next storage area has been allocated in different ways.
  • the global write pointer of the next storage area records the total allocated space size of the circular storage queue. At this time, if the global write pointer of the next storage area is larger than the total space size of the circular storage queue, the computer device determines that the next storage area has been allocated. If the global write pointer of the next storage area is less than or equal to the total space size of the circular storage queue, the computer device determines that the next storage area has not been allocated. For example, a circular storage queue includes 10 storage areas. Each storage area includes 100 bytes. After each cycle, the computer device does not clear the global write pointer. At this time, if the global write pointer of the next storage area is greater than 1000, the computer device determines that the next storage area has been allocated. If the global write pointer of the next storage area is less than 1000, the computer device determines that the next storage area has not been allocated.
  • FIG. 6 is a schematic structural diagram of the global write pointer provided in this application.
  • the current global write pointer includes a current write area pointer 601 and a write offset pointer 602 within the current area.
  • the current write area pointer 601 is used to represent the current storage area. Assume that the circular storage queue includes 10 storage areas.
  • the computer device starts writing data from the first storage area among the 10 storage areas. When the current write area pointer 601 is 1, it indicates that the current storage area is the first storage area among the 10 storage areas. When the current write area pointer 601 is 2, it indicates that the current storage area is the second storage area among the 10 storage areas.
  • the current write area pointer 601 will be greater than 10 as the cycle increases. For example, when the current write area pointer 601 is 11, it indicates that the current storage area is the first storage area among the 10 storage areas. When the current write area pointer 601 is 12, it indicates that the current storage area is the second storage area among the 10 storage areas.
  • the global write pointer of the next storage area is simply called the next global write pointer. If the write area pointer of the next global write pointer is greater than the number M of storage areas, the computer device determines that the next storage area has been allocated. If the write area pointer of the next global write pointer is less than or equal to the number M of storage areas, the computer device determines that the next storage area has not been allocated. If the next storage area has been allocated, the computer device executes step 410 . If the next storage area has not been allocated, the computer device executes step 412 .
  • the write offset pointer 602 in the current area is used to represent the offset of the current byte to the starting position of the current storage area. Assume that the current storage area includes 100 bytes. The 100 bytes are sorted in logical direction. When the write offset pointer 602 in the current area is equal to 5, it indicates that the current byte is the fifth byte among the 100 bytes. When the write offset pointer 602 in the current area is equal to 6, it indicates that the current byte is the sixth byte among the 100 bytes. If the computer device does not clear the write offset pointer 602 in the current area, then the write offset pointer 602 in the current area will be greater than 100 as the cycle increases.
  • the current global write pointer includes 64 bits.
  • the current write area pointer 601 includes the first 48 bits among the 64 bits.
  • the write offset pointer 602 in the current region includes the last 16 bits of the 64 bits.
  • step 410 the computer device determines whether the next storage area is completely written. According to the foregoing description of the circular storage queue, each storage area corresponds to a write flag. Therefore, the next storage area corresponds to the next write mark.
  • the computer device can obtain the next write identification.
  • the next write mark represents the data size of the data stored in the last cycle. For example, assume that the next storage area includes 100 bytes. When the next write flag is equal to 40, the data representing the data stored in the next storage area in the last cycle is 40 bytes. It should be understood that if the computer device does not clear the next write flag, then as the cycle increases, the value of the next write flag will be greater than the total space size of the next storage area. For example, when the next write flag is equal to 140, it indicates that the data stored in the next storage area in the last cycle is 40 bytes.
  • the computer device determines that the next storage area is completely written. For example, the total space size of the next storage area is 100 bytes.
  • the next write flag is equal to 200, the computer device determines that the next storage area is completely written. If the total space size of the next storage area divided by the next write mark is not equal to an integer, the computer device determines that the next storage area has not been completely written. For example, the total space size of the next storage area is 100 bytes.
  • the next write flag is equal to 205, the computer device determines that the next storage area has not been completely written. If the next storage area is not completely written, the computer device executes step 411 . If the next storage area is completely written, the computer device executes step 412 .
  • the computer device can obtain the current global read pointer. If the current global read pointer points to a storage area other than the next storage area, and the total space size of the next write mark except the next storage area is equal to an integer, then the computer device determines that the next storage area is completely written. If the current global read pointer points to the next storage area, or the total space size of the storage area divided by the write mark of the next storage area is not equal to an integer, then the computer device determines that the next storage area has not been completely written.
  • step 411 end.
  • ending may mean that the current thread in the computer device gives up storing the current data, or the current thread in the computer device returns to step 401 .
  • step 412 the computer device determines whether the current global write pointer has been modified.
  • the computer device obtains the current global write pointer.
  • the computer device obtains the current global write pointer here again. If the current global write pointer acquired twice is the same, the computer device determines that the current global write pointer has not been modified. If the current global write pointer acquired twice is different, the computer device determines that the current global write pointer has not been modified. If the current global write pointer has not been modified, step 413 is executed. If the current global write pointer is modified, step 401 is executed.
  • step 413 the computer device clears the write flag of the next storage area.
  • the next storage area corresponds to the next write mark.
  • step 414 the computer device uses the global write pointer of the next storage area as the current global write pointer.
  • the current global write pointer may be the first global write pointer, the second global write pointer, or the third global write pointer.
  • the current storage area may be the first storage area or the second storage area.
  • FIG. 7 is a first schematic flowchart of the method for reading data provided in this application. As shown in FIG. 7, writing data includes the following steps.
  • the computer device obtains the current global read pointer, and determines the current storage area according to the current global read pointer.
  • the current thread of the computer device obtains the current global read pointer of the circular storage queue.
  • the current global read pointer is also called the current global read pointer.
  • the current global read pointer points to the current sub-area of the current storage area among the M storage areas. For example, the current global read pointer points to the start of the current subregion. The starting position is the current byte.
  • the computer device can obtain the current global read pointer from the queue head of the circular storage queue.
  • the computer device determines whether the current storage area is overwritten.
  • the current global write pointer includes a current write area pointer and a write offset pointer within the current area.
  • the current global read pointer may also include a current read area pointer and a read offset pointer within the current area.
  • the current read area pointer is used to represent the current storage area.
  • the read offset pointer in the current area is used to represent the offset of the current byte to the starting position of the current storage area.
  • the current storage area pointed to by the current global write pointer and the current storage area pointed to by the current global read pointer may be the same storage area or may not be the same area. If the difference between the current write area pointer and the current read area pointer is greater than M, the computer device determines that the current storage area is overwritten. If the difference between the current write area pointer and the current read area pointer is less than or equal to M, the computer device determines that the current storage area is not overwritten. If the current storage area is not overwritten, step 704 is executed. If the current storage area is overwritten, step 703 is executed.
  • step 703 the computer device clears the current read flag to zero.
  • the computer device updates the current global read pointer.
  • the current storage area corresponds to the current write flag and the current read flag.
  • a computer device when a computer device writes data, it may overwrite unread data. At this time, the current read identifier of the computer device cannot be updated normally. The computer device cannot determine whether to perform step 706 through the subsequent step 704 . Therefore, in the aforementioned step 413 of FIG. 4 , the computer device clears the current write flag. In this step, the computer device clears the current read flag to zero.
  • the difference between the current read area pointer and the current write area pointer is greater than M, it indicates that the current storage area is overwritten. If the computer device still starts to read data from the current byte, the data between the current global write pointer and the current byte will be lost. To this end, the computer device updates the current global read pointer.
  • step 704 the computer device determines whether the current write flag is greater than the current read flag. If the current write flag is greater than the current read flag, it means that unread data has been written into the current sub-area, and the computer device can read the data in the current sub-area. If the current write flag is less than or equal to the current read flag, it means that no unread data has been written into the current sub-area, and the computer device cannot read the data in the current sub-area. Therefore, if the current write flag is equal to the current read flag, the computer device executes step 705 . If the current write flag is greater than the current read flag, the computer device executes step 706 .
  • step 705 end. Wherein, ending may mean that the current thread in the computer device gives up storing the current data, or the current thread in the computer device returns to step 701 .
  • the computer device determines whether the current global write pointer points to the current storage area.
  • the current global write pointer includes a current write area pointer and a write offset pointer within the current area.
  • the circular storage queue includes 10 storage areas.
  • the current storage area is the first storage area among the 10 storage areas.
  • the remainder of dividing the current write area pointer by 10 is equal to 1, it means that the current global write pointer points to the current storage area.
  • the current write area pointer is equal to 1, 11 or 21 and so on.
  • the computer device executes step 707 .
  • the computer device performs step 709 .
  • step 707 the computer device determines whether the write offset pointer in the current region in the current global write pointer is equal to the current write flag. If the write offset pointer in the current area is not equal to the current write flag, it indicates that the commit status of the current storage area is incomplete commit. If the write offset pointer in the current area is equal to the current write flag, it indicates that the commit state of the current storage area is a complete commit. For the description of the commit status, please refer to the relevant description in the foregoing Figure 2 . Therefore, if the write offset pointer in the current area is not equal to the current write flag, the computer device executes step 708 . If the write offset pointer in the current area is equal to the current write flag, the computer device executes step 710 . Wherein, the write offset pointer in the current area points to the first byte in the current storage area. The first byte is any byte in the current storage area except the current byte.
  • step 708 end. Wherein, ending may mean that the current thread in the computer device gives up storing the current data, or the current thread in the computer device returns to step 701 .
  • the computer device determines whether the current storage area is completely written. If the current write flag divided by the total space size of the current storage area is equal to an integer, the computer device determines that the current storage area is completely written. For example, the total space size of the current storage area is 100 bytes. When the current write flag is equal to 200, the computer device determines that the current storage area is completely written. If the current write flag divided by the total space size of the current storage area is not equal to an integer, the computer device determines that the current storage area has not been completely written. For example, the total space size of the current storage area is 100 bytes. When the current write flag is equal to 205, the computer device determines that the current storage area has not been completely written.
  • the computer device executes step 705 . If the current storage area is completely written, the computer device executes step 710 .
  • step 710 the computer device determines whether the current sub-region belongs to an invalid sub-region. According to the foregoing description, it can be seen that the current global read pointer points to the current sub-area. If the current sub-area does not belong to an invalid sub-area, the computer device executes step 711 . If the current sub-area belongs to an invalid sub-area, step 712 is executed. For the description of the invalid sub-region, reference may be made to the relevant description in FIG. 4 above. For example, the computer device can determine whether the current sub-area belongs to an invalid sub-area through the target identifier. If the current sub-area includes the corresponding target identifier, the computer device determines that the current sub-area belongs to an invalid sub-area. If the current sub-area does not include the corresponding target identifier, the computer device determines that the current sub-area does not belong to an invalid sub-area.
  • step 711 the computer device reads the current data in the current sub-area.
  • step 712 the computer device determines whether the current storage area is overwritten. If the current global write pointer moves, the current storage area may be overwritten. Therefore, the computer device again determines whether the current storage area is overwritten. Specifically, the computer device obtains the current writing area pointer and the current writing area pointer. If the difference between the current write area pointer and the current read area pointer is greater than M, the computer device determines that the current storage area is overwritten. If the difference between the current write area pointer and the current read area pointer is less than or equal to M, the computer device determines that the current storage area is not overwritten. If the current storage area is not overwritten, the computer device executes step 713 . If the current storage area is overwritten, the computer device executes step 703 .
  • step 713 the computer device determines whether the current sub-region belongs to an invalid sub-region. If the current sub-area belongs to an invalid sub-area, step 715 is executed. If the current sub-area does not belong to an invalid sub-area, step 714 is executed.
  • step 714 the computer device updates the global read pointer and the current read identifier.
  • the updated current global read pointer points to the next sub-region of the current sub-region.
  • the updated current read identifier is equal to the sum of the current read identifier and X.
  • X is the data size of the current data read by the computer device.
  • step 715 the computer device determines whether the current write area pointer is greater than the current read area pointer. If the current write area pointer is greater than the current read area pointer, the computer device executes step 717 . If the current write area pointer is less than or equal to the current read area pointer, the computer device executes step 716 .
  • step 716 end.
  • ending may mean that the current thread in the computer device gives up storing the current data, or the current thread in the computer device returns to step 701 .
  • step 717 the computer device updates the current global read pointer.
  • the computer device clears the current read flag to zero.
  • the updated current global read pointer points to the next storage area of the current storage area. Specifically, the updated current global read pointer points to the first sub-area of the next storage area.
  • the current global write pointer may be the first global read pointer, the second global read pointer, and so on.
  • the current storage area may be the first storage area or the second storage area.
  • the current global write pointer corresponds to the current storage area.
  • the current global read pointer corresponds to the current storage area.
  • the two current storage areas may or may not be the same storage area.
  • FIG. 4 is a flowchart of a method for writing data
  • FIG. 7 is a flowchart of a method for reading data.
  • writing data and reading data are correlated. Therefore, regarding the description in FIG. 7 , reference may be made to the description in FIG. 4 .
  • each storage area may also include corresponding write area identifiers and read area identifiers.
  • the current storage area corresponds to the current write area identifier and the current read area identifier.
  • the current write area identifier is equal to the current write area pointer.
  • the current write area ID and the current write ID can be recorded in one field.
  • one field includes 64 bits.
  • the current write area identifier includes the first 48 bits of the 64 bits.
  • the current write flag includes the last 16 bits of the 64 bits.
  • the current read area identifier is equal to the current read area pointer.
  • the current read area ID and the current read ID can be recorded in one field.
  • one field includes 64 bits.
  • the current read area identifier includes the first 48 bits of the 64 bits.
  • the current read identifier includes the last 16 bits of the 64 bits.
  • Current write area identification and current read area identification can be used to avoid the ABA problem in CAS.
  • FIG. 8 is a second schematic flowchart of the method for writing data provided in this application. As shown in FIG. 8, writing data includes the following steps.
  • step 801 the computer device obtains the current global write pointer, and determines the current storage area according to the current global write pointer.
  • step 802 the computer device determines whether there is enough free space in the current storage area according to the current global write pointer and the current data size. If there is enough remaining space, the computer device executes step 803 . If there is not enough remaining space, the computer device executes step 806 .
  • step 803 the computer device determines whether the head grabbing is successful. If the head grabbing is successful, the computer device executes step 804 . If the head grabbing fails, the computer device executes step 801 .
  • step 804 the computer device executes the write process.
  • step 805 the computer device updates the current write flag of the current storage space.
  • step 806 the computer device determines whether the remaining space is an invalid sub-region. If the remaining space is not an invalid sub-area, go to step 807. If the remaining space is an invalid sub-area, go to step 808 .
  • step 807 the computer device regards the remaining space as an invalid sub-area.
  • step 808 the computer device calculates the global write pointer of the next storage area according to the current global write pointer.
  • step 809 the computer device determines whether the next storage area has been allocated according to the global write pointer of the next storage area. If the next storage area has been allocated, the computer device executes step 810 . If the next storage area has not been allocated, the computer device executes step 812 .
  • step 810 the computer device determines whether the next storage area is completely written. If the next storage area is not completely written, the computer device executes step 811 . If the next storage area is completely written, the computer device executes step 812 .
  • step 811 end.
  • step 812 the computer device determines whether the next storage area is completely read. According to the foregoing description of the circular storage queue, each storage area corresponds to a read flag. Therefore, the next storage area corresponds to the next read mark.
  • the computer device can obtain the next read identification.
  • the next read flag represents the data size of the data that has been read in the next storage area in the last cycle. For example, assume that the next storage area includes 100 bytes. When the next read flag is equal to 40, the data size representing the data read in the last cycle of the next storage area is 40 bytes. It should be understood that if the computer device does not clear the next read flag, then as the cycle increases, the value of the next read flag will be greater than the total space size of the next storage area. For example, when the next read flag is equal to 140, the data size representing the data read in the last cycle of the next storage area is 40 bytes.
  • the computer device determines that the next storage area has been completely read. For example, the total space size of the next storage area is 100 bytes.
  • the next read flag is equal to 200, the computer device determines that the next storage area is completely read. If the total space size divided by the next read identifier of the next storage area is not equal to an integer, the computer device determines that the next storage area has not been completely read. For example, the total space size of the next storage area is 100 bytes.
  • the next read flag is equal to 205, the computer device determines that the next storage area has not been completely read. If the next storage area has not been completely read, the computer device executes step 811 . If the next storage area is completely read, the computer device executes step 813 .
  • step 813 the computer device uses the global write pointer of the next storage area as the current global write pointer.
  • step 812 the computer device may execute step 812 first. If the next storage area is completely read, the computer device executes step 810 .
  • FIG. 9 is a second schematic flowchart of the method for reading data provided in this application. As shown in Fig. 9, the method for reading data includes the following steps.
  • step 901 the computer device obtains the current global read pointer, and determines the current storage area according to the current global read pointer.
  • step 902 the computer device determines whether the current write flag is greater than the current read flag. If the current write flag is greater than the current read flag, the computer device executes step 904 . If the current write flag is less than or equal to the current read flag, the computer device executes step 903 .
  • step 903 end.
  • step 904 the computer device determines whether the current global write pointer points to the current storage area. If the current global write pointer points to the current storage area, the computer device executes step 905 . If the current global write points to a storage area other than the current storage area, the computer device executes step 907 .
  • step 905 the computer device determines whether the write offset pointer in the current area is equal to the current write flag. If the write offset pointer in the current area is not equal to the current write flag, the computer device executes step 906 . If the write offset pointer in the current area is equal to the current write flag, the computer device executes step 908 .
  • step 906 end.
  • step 907 the computer device determines whether the current storage area is completely written. If the current storage area has not been completely written, the computer device executes step 903 . If the current storage area is completely written, the computer device executes step 908 .
  • step 908 the computer device determines whether the current global read pointer has been modified.
  • the computer device obtains the current global read pointer.
  • step 909 the computer device determines whether the current sub-area belongs to an invalid sub-area. According to the foregoing description, it can be seen that the current global read pointer points to the current sub-area. If the current sub-area does not belong to an invalid sub-area, the computer device executes step 910 . If the current sub-area belongs to an invalid sub-area, the computer device executes step 912 .
  • step 910 the computer device reads the current data in the current sub-area.
  • the current thread of the computer device performs head-grabbing operations. If the head grabbing is successful, the computer device reads the current data in the current sub-area. If the head grab is successful, it means that the computer device has updated the current global read pointer. The updated current global read pointer points to the first byte of the next sub-area of the current sub-area. The computer device uses the updated current global read pointer as the current global read pointer. If the head grabbing fails, the computer device executes step 906 .
  • step 911 the computer device updates the current read ID.
  • the updated current read identifier is equal to the sum of the data size of the current data and the current read identifier. For example, the current read ID is equal to 250. The data size of the current data is 40 bytes. Then the updated current read identifier is equal to 290.
  • step 912 the computer device determines whether the current write area pointer is greater than the current read area pointer. If the current writing area pointer is greater than the current reading area pointer, the computer device executes step 913 . If the current writing area pointer is less than or equal to the current reading area pointer, the computer device executes step 903 .
  • step 913 the computer device updates the current global read pointer and the current global read pointer.
  • the updated current global read pointer points to the next storage area of the current storage area. Specifically, the updated current global read pointer points to the first sub-area of the next storage area.
  • the computer device updates the current global read pointer.
  • the updated current global read pointer is equal to the sum of the current global read pointer and the space size of the target invalid sub-region. For the description of the target invalid sub-area, reference may be made to the relevant description in FIG. 4 above.
  • step 901 reference may be made to the description of step 701 in FIG. 7 above.
  • step 902 to step 907 reference may be made to the description in the aforementioned step 704 to step 709.
  • step 907 reference may be made to the description of the aforementioned step 713.
  • step 910 and step 911 reference may be made to the description of step 714 above.
  • step 912 reference may be made to the description of the aforementioned step 715.
  • FIG. 10 is a schematic structural diagram of a data processing device provided in this application.
  • the data processing apparatus 1000 includes a first acquisition module 1001 , a second acquisition module 1002 , a processing module 1003 and a reading module 1004 .
  • the first acquiring module 1001 is configured to acquire the first global read pointer of the circular storage queue.
  • the circular storage queue includes M storage areas. M is an integer greater than 1.
  • the first global read pointer points to the first storage area in the M storage areas.
  • the second acquiring module 1002 is configured to acquire the first write mark of the first storage area.
  • the first write mark represents the space size of the stored data in the first storage area.
  • the processing module 1003 is configured to determine the size of the allocated space in the first storage area.
  • the reading module 1004 is configured to read the first data in the first sub-area if the first condition is satisfied.
  • the first condition includes: the space size of the stored data in the first storage area is equal to the allocated space size in the first storage area.
  • the data processing apparatus 1000 may further include an updating module, a clearing module, and the like.
  • the modules in the program running device are specifically configured to execute all or part of the operations that can be performed by the computer device in the embodiment corresponding to FIG. 2 , FIG. 4 , FIG. 7 , FIG. 8 or FIG. 9 .
  • FIG. 11 is a schematic structural diagram of a computer device provided in this application.
  • the computer device 1100 in this application may be a desktop computer, a notebook, a smart phone, a switch, a base station, and the like.
  • a computer device 1100 includes a processor 1101 and a memory 1103 .
  • the processor 1101 may be a central processing unit (central processing unit, CPU), a network processor (network processor, NP) or a combination of CPU and NP.
  • the processor 1101 may further include a hardware chip or other general-purpose processors.
  • the aforementioned hardware chip may be an application specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof.
  • ASIC application specific integrated circuit
  • PLD programmable logic device
  • the above PLD can be complex programmable logic device (complex programmable logic device, CPLD), field programmable logic gate array (field-programmable gate array, FPGA), general array logic (generic array logic, GAL) and other programmable logic devices , discrete gate or transistor logic devices, discrete hardware components, etc., or any combination thereof.
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • Memory 1103 may be volatile memory or nonvolatile memory, or may include both volatile and nonvolatile memory.
  • the non-volatile memory can be read-only memory (read-only memory, ROM), programmable read-only memory (programmable ROM, PROM), erasable programmable read-only memory (erasable PROM, EPROM), electrically programmable Erases programmable read-only memory (electrically EPROM, EEPROM) or flash memory.
  • Volatile memory can be random access memory (RAM), which acts as external cache memory.
  • RAM random access memory
  • RAM random access memory
  • many forms of RAM are available such as static random access memory (static RAM, SRAM), dynamic random access memory (dynamic RAM, DRAM), synchronous dynamic random access memory (synchronous DRAM, SDRAM), etc.
  • the first global read pointer of the circular storage queue is stored in the memory 1103 .
  • the circular storage queue includes M storage areas. M is an integer greater than 1.
  • the first global read pointer points to the first storage area in the M storage areas.
  • the first write flag of the first storage area is also stored in the memory 1103 .
  • the first write mark represents the space size of the stored data in the first storage area.
  • the processor 1101 is configured to determine the size of the allocated space in the first storage area.
  • the processor 1101 is configured to read first data in the first sub-area if the first condition is satisfied.
  • the first condition includes: the space size of the stored data in the first storage area is equal to the allocated space size in the first storage area.
  • the computer device further includes a transceiver 1102 .
  • the transceiver 1102 may be a fiber optic transceiver, a wireless radio frequency module, and the like.
  • computer programs that can be executed by the processor 1101 are stored in the memory 1103 .
  • the processor 1101 reads and executes the computer program, it can perform all or part of the operations that can be performed in the data processing method in FIG. 2 , FIG. 4 , FIG. 7 , FIG. 8 or FIG. 9 .
  • the present application also provides a digital processing chip.
  • the digital processing chip integrates a circuit and one or more interfaces for realizing the functions of the above-mentioned processor 1101 .
  • the digital processing chip can complete the method steps in any one or more of the foregoing embodiments.
  • the memory is not integrated in the digital processing chip, it can be connected to an external memory through an interface.
  • the digital processing chip realizes the data processing method in the above-mentioned Fig. 2, Fig. 4, Fig. 7, Fig. 8 or Fig. 9 according to the program code stored in the external memory.

Landscapes

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

Abstract

一种数据处理方法,应用于计算机领域。该方法包括以下步骤:获取循环存储队列的第一全局读指针。循环存储队列包括多个存储区域。第一全局读指针指向多个存储区域中的第一存储区域(201)。获取第一存储区域的第一写标识(202)。第一写标识表征第一存储区域中已存储数据的空间大小。第一全局写指针确定第一存储区域中已被分配的空间大小。若第一存储区域中已存储数据的空间大小等于第一存储区域中已被分配的空间大小,则读取第一子区域中的第一数据(203)。上述方法通过增加第一写标识,使得乱序commit不会影响读取的数据的正确性,可以通过乱序commit提高***的运行效率。

Description

数据处理方法、数据处理装置以及相关设备
本申请要求于2021年8月31日提交中国国家知识产权局、申请号CN202111015761.0、申请名称为“数据处理方法、数据处理装置以及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机领域,尤其涉及数据处理方法、数据处理装置以及相关设备。
背景技术
在操作***中,循环存储队列是一种特殊的先进先出队列。循环存储队列将存储空间中的最后一个位置连接第一个位置,形成逻辑上的环状空间。
图1为循环存储队列的结构示意图。如图1所示,循环存储队列包括对应的全局写指针和全局读指针。沿逆时针方向,全局写指针和全局读指针之间的区域为存储区域b。全局读指针和全局写指针之间的区域为区域a。区域a中的数据即将被读取,区域b即将被写入数据。随着数据的写入和读取,全局写指针和全局读指针沿逆时针方向移动。例如,在线程1分配到了子区域b1后,全局写指针移动至子区域b2。在线程2分配到了子区域b2后,全局写指针移动至剩余区域b3。在写入数据后,不同的线程执行顺序commit。具体地,在子区域b1中写入数据后,线程1执行commit操作。commit操作表征子区域b1中已写入数据。子区域b1中的数据可以被读取。类似地,在子区域b2中写入数据后,线程2执行commit操作。commit操作表征子区域b2中已写入数据。子区域b2中的数据可以被读取。若不同的线程执行乱序commit,则会影响数据的读取。具体地,若线程2提前进行commit操作,在全局读指针移动至子区域b1后,则可能存在线程读取子区域b1中的数据。但是,线程1并未写完数据。因此,线程读取的数据可能是错误的。
在线程2先写入数据后,线程2会进入等待状态,直至线程1完成commit操作。在等待期间,线程2需要频繁判断线程1是否完成commit操作,从而降低了***的运行效率。
发明内容
本申请提供了一种数据处理方法、数据处理装置以及相关设备。在申请中,通过增加第一写标识,使得乱序commit不会影响读取的数据的正确性。因此,本申请可以通过乱序commit提高***的运行效率。
本申请第一方面提供了一种数据处理方法。数据处理方法可以应用于包括循环存储队列的操作***中。数据处理方法的执行主体可以线程、操作***或安装有操作***的计算机设备。后续将以执行主体是计算机设备为例,对数据处理方法进行描述。数据处理方法包括以下步骤:计算机设备获取循环存储队列的第一全局读指针。循环存储队列包括M个存储区域。M为大于1的整数。每个存储区域在逻辑上连续。第一全局读指针指向M个存储区域中的第一存储区域。计算机设备获取第一存储区域的第一写标识。M个存储区域中 的每个存储区域对应一个写标识。第一存储区域和第一写标识对应。第一写标识表征第一存储区域中已存储数据的空间大小。计算机设备确定第一存储区域中已被分配的空间大小。通过第一写标识,计算机设备可以确定第一存储区域的commit状态。commit状态包括完全commit和未完全commit。完全commit表示第一存储区域中已存储数据的空间大小等于第一存储区域中已被分配的空间大小。未完全commit表征第一存储区域中已存储数据的空间大小小于第一存储区域中已被分配的空间大小。若满足第一条件,则计算机设备读取第一子区域中的第一数据。第一条件包括:第一存储区域的commit状态为完全commit。
在申请中,第一写标识表征的是数据大小。因此,在第一存储区域中,乱序commit并不会影响对commit状态的判断,即乱序commit不会影响读取的数据的正确性。因此,在第一存储区域中写入数据后,线程可以不需要等待其它线程完成commit操作,从而提高了***的运行效率。
在第一方面的一种可选方式中,若第一全局写指针指向第一存储区域以外的存储区域,则计算机设备确定第一存储区域中已被分配的空间大小等于第一存储区域总的空间大小。和/或,若第一全局写指针指向第一存储区域,则计算机设备确定第一存储区域中已被分配的空间大小或等于第一字节的位置和第一存储区域的起始位置的差值。第一全局写指针指向第一存储区域中第一字节。其中,通过额外的标识也可以记录第一存储区域中已被分配的空间大小。在本申请中,通过第一全局写指针来确定第一存储区域中已被分配的空间大小,可以提高第一全局写指针的利用率,节约***的存储空间。
在第一方面的一种可选方式中,在读取第一子区域中的第一数据前,数据处理方法还包括:计算机设备获取第一存储区域的第一读标识。第一读标识表征第一存储区域中已被读取的数据的数据大小。计算机设备确定第一写标识和第一读标识的大小关系。第一条件还包括:第一写标识大于第一读标识。其中,当第一写标识等于第一读标识时,表征第一子区域中还未写入未被读取的数据,计算机设备无法读取第一数据。因此,计算机设备可以无需判断第一存储区域的commit状态,从而节约***的处理资源。
在第一方面的一种可选方式中,第一子区域和第一数据的大小为X字节。X为大于0的整数。在读取第一子区域中的第一数据后,数据处理方法还包括:计算机设备通过X更新第一存储区域的第一读标识。更新后的第一读标识等于第一读标识和X之和。
在第一方面的一种可选方式中,数据处理方法还包括:计算机设备获取循环存储队列的第二全局写指针。第二全局写指针指向第一存储区域中的第二字节。第一子区域的起始位置为第二字节。若第二字节的位置与第一存储区域的终点位置的差值大于或等于X,则计算机设备从第二字节中写入第一数据。若第二字节的位置与第一存储区域的终点位置的差值小于X,则计算机设备不在第二字节开始写入第一数据。其中,差值小于X表征第一存储区域的剩余空间不足。当第一存储区域的剩余空间不足时,当前线程只能在剩余空间写入第一数据的部分数据。当前线程还需要在下一个存储区域的第一个子区域写入第一数据的另一部分数据。在多线程并发的场景中,当前线程可能无法被分配到下一个存储区域的第一个子区域。此时,第一数据的另一部分数据无法被写入到第一个子区域,从而降低了***的可靠性。差值大于或等于X表征第一存储区域有足够的剩余空间。计算机设备只在有足够的剩余空间时,才在剩余空间中写入第一数据。因此,本申请可以提高***的可 靠性。
在第一方面的一种可选方式中,数据处理方法还包括:计算机设备获取循环存储队列的第三全局写指针。第三全局写指针指向第一存储区域的第三字节。计算机设备获取待写入的第二数据的大小。第二数据的大小为N字节。若第三字节的位置与第一存储区域的终点位置表征第一存储区域的剩余区域小于N字节,则计算机设备为剩余区域添加目标标识。目标标识用于表征剩余区域为无效子区域。例如,计算机设备可以在剩余区域的头部添加目标标识。通过增加目标标识,可以避免计算机设备读取到错误的数据。例如,错误的数据可能是上一个循环中写入的已被读取过的数据。因此,本申请可以提高***的可靠性。
在第一方面的一种可选方式中,在读取第一子区域中的第一数据前,数据处理方法还包括:计算机设备确定第一子区域是否为无效子区域。第一条件还包括:第一子区域不是无效子区域。若第一子区域是无效子区域,则计算机设备不读取第一子区域中的数据。其中,若计算机设备读取第一子区域中的无效数据,则会浪费***资源。本申请通过在读取第一数据前确定第一子区域是否为无效子区域,可以避免浪费***资源。
在第一方面的一种可选方式中,数据处理方法还包括:若满足第二条件,则计算机设备更新第三全局写指针。更新后的第三全局写指针指向第二存储区域。第二存储区域为第一存储区域的下一个存储区域。第二条件包括:第二存储区域未被分配过。或第三全局读指针指向第二存储区域以外的存储区域。第二存储区域的第二写标识除以第二存储区域的总的空间大小等于整数。第二写标识表征第二存储区域中已存储数据的空间大小。其中,当第三全局读指针指向第二存储区域以外的存储区域,第二存储区域的第二写标识除以第二存储区域的总的空间大小等于整数时,表示在最后一次循环中,第二存储区域中的数据已经被完全写入。当第三全局读指针指向第二存储区域,或第二存储区域的第二写标识除以第二存储区域的总的空间大小不等于整数时,表示在上一个循环中,第二存储区域中的数据未被完全写入。在第二存储区域中的数据还未被完全写入时,计算机设备不能更新第三全局写指针。否则可能产生两个线程同时写入数据到相同的字节,从而造成***异常。在本申请中,通过在更新第三全局写指针前确定第二存储区域中的数据是否已经被完全写入,可以提高***的稳定性。
在第一方面的一种可选方式中,在计算机设备更新第三全局写指针前,数据处理方法还包括:计算机设备将第二写标识清零。第一全局读指针包括第一读区域指针和第一区域内读偏移指针。第一读区域指针指向第一存储区域。第一区域内读偏移指针指向第一存储区域中的第二字节。第一全局写指针包括第一写区域指针和第一区域内写偏移指针。在计算机设备读取第一子区域中的第一数据后,数据处理方法还包括:若第一读区域指针和第一写区域指针的差值大于M,则计算机设备将第一读标识清零。其中,为了提高数据写入的效率,计算机设备在写入数据时,可能会覆盖还未被读取的数据。当第一写标识等于第一读标识时,第一子区域中的数据可能未被读取。因此,若计算机设备仍然通过第一写标识的第一读标识大小关系确定是否执行commit状态的判断,则可能造成***异常,例如数据无法被读取。因此,本申请通过清零可以提高***的可靠性。
在第一方面的一种可选方式中,数据处理方法还包括:若第一读区域指针和第一写区域指针的差值大于M,则更新第一读区域指针。更新后的第一读区域指针等于第一写区域 指针和Z的差值,Z=M-1。其中,若差值大于M,则表征第一子区域写入的数据在未被读取的情况下,被覆盖写入。若计算机设备仍然从第一子区域开始读取数据,则会丢失第一全局写指针到第一子区域之间的数据。在本申请中,通过将第一读区域指针更新至第一写区域指针的前一个存储区域,可以尽量减少丢失的数据量,提高***的可靠性。
在第一方面的一种可选方式中,第二条件还包括:第二存储区域的第二读标识除以第二存储区域的总的空间大小等于整数。第二读标识表征第二存储区域中已被读取的数据的数据大小。其中,当第二读标识除以第二存储区域的总的空间大小等于整数时,表示在上一个循环中,第二存储区域中的数据已经被完全读取。当第二读标识除以第二存储区域的总的空间大小不等于整数时,表示在上一个循环中,第二存储区域中的数据未被完全读取。通过增加第二条件的内容,可以避免计算机设备在写入数据时覆盖还未被读取的数据,从而减少数据的丢失,提高***的可靠性。
本申请第二方面提供了一种数据处理装置。数据处理装置包括第一获取模块、第二获取模块、处理模块和读取模块。第一获取模块用于获取循环存储队列的第一全局读指针。循环存储队列包括M个存储区域。M为大于1的整数。第一全局读指针指向M个存储区域中的第一存储区域。第二获取模块用于获取第一存储区域的第一写标识。第一写标识表征第一存储区域已存储数据的空间大小。处理模块用于确定第一存储区域中已被分配的空间大小。读取模块用于若满足第一条件,则读取第一子区域中的第一数据。第一条件包括:第一存储区域中已存储数据的空间大小等于第一存储区域中已被分配的空间大小。
在第二方面的一种可选方式中,处理模块用于若第一全局写指针指向第一存储区域以外的存储区域,则确定第一存储区域中已被分配的空间大小等于第一存储区域总的空间大小。和/或,处理模块用于若第一全局写指针指向第一存储区域,则确定第一存储区域中已被分配的空间大小等于第一字节的位置和第一存储区域的起始位置的差值。第一全局写指针指向第一存储区域中的第一字节。
在第二方面的一种可选方式中,第一获取模块还用于获取第一存储区域的第一读标识。第一读标识表征第一存储区域中已被读取的数据的数据大小。处理模块还用于确定第一写标识和第一读标识的大小关系;第一条件还包括:第一写标识大于第一读标识。
在第二方面的一种可选方式中,数据处理装置还包括更新模块。第一子区域和第一数据的大小为X字节。X为大于0的整数。更新模块用于通过X更新第一存储区域的第一读标识。更新后的第一读标识等于第一读标识和X之和。
在第二方面的一种可选方式中,第一获取模块还用于获取循环存储队列的第二全局写指针。第二全局写指针指向第一存储区域中的第二字节。第一存储区域的起始位置为第二字节。数据处理装置还包括写入模块。写入模块用于若第二字节的位置与第一存储区域的终点位置的差值大于或等于X,则在第一子区域中写入第一数据。
在第二方面的一种可选方式中,第一获取模块还用于获取循环存储队列的第三全局写指针。第三全局写指针指向第一存储区域的第三字节。第一获取模块还用于获取待写入的第二数据的大小。第二数据的大小为N字节。数据处理装置还包括添加模块。添加模块用于若第三字节的位置与第一存储区域的终点位置表征第一存储区域的剩余区域小于N字节,则为剩余区域添加目标标识。目标标识用于表征剩余区域为无效子区域。
在第二方面的一种可选方式中,处理模块还用于确定第一子区域是否为无效子区域。第一条件还包括:第一子区域不是无效子区域。
在第二方面的一种可选方式中,数据处理装置还包括更新模块。更新模块用于若满足第二条件,则更新第三全局写指针。更新后的第三全局写指针指向第二存储区域的第一个字节。第二存储区域为第一存储区域的下一个存储区域。第二条件包括:第二存储区域未分配过,或第三全局读指针指向第二存储区域以外的存储区域。第二存储区域的第二写标识除以第二存储区域的总的空间大小等于整数。第二写标识表征第二存储区域中已存储数据的空间大小。
在第二方面的一种可选方式中,数据处理装置还包括清零模块。清零模块用于将第二写标识清零。第一全局读指针包括第一读区域指针和第一区域内读偏移指针。第一读区域指针指向第一存储区域。第一区域内读偏移指针指向第一存储区域中的第二字节。第一全局写指针包括第一写区域指针和第一区域内写偏移指针。清零模块还用于若第一读区域指针和第一写区域指针的差值大于M,则将第一存储区域中的第一读标识清零。
在第二方面的一种可选方式中,更新模块还用于若第一读区域指针和第一写区域指针的差值大于M,则更新第一读区域指针。更新后的第一读区域指针等于第一写区域指针和Z的差值。Z=M-1。
在第二方面的一种可选方式中,第二条件还包括:第二存储区域的第二读标识除以第二存储区域的总的空间大小等于整数。第二读标识表征第二存储区域中已被读取的数据的数据大小。
本申请第三方面提供了一种计算机设备。计算机设备包括存储器和处理器。存储器中存储有循环存储队列的第一全局读指针。循环存储队列包括M个存储区域。M为大于1的整数。第一全局读指针指向M个存储区域中的第一存储区域。存储器中还存储有第一存储区域的第一写标识。第一写标识表征第一存储区域中已存储数据的空间大小。处理器用于确定第一存储区域中已被分配的空间大小。处理器用于若满足第一条件,则读取第一子区域中的第一数据。第一条件包括:第一存储区域中已存储数据的空间大小等于第一存储区域中已被分配的空间大小。
在第三方面的一种可选方式中,处理器用于若第一全局写指针指向第一存储区域以外的存储区域,则确定第一存储区域中已被分配的空间大小等于第一存储区域总的空间大小。和/或,处理器用于若第一全局写指针指向第一存储区域,则确定第一存储区域中已被分配的空间大小等于第一字节的位置和第一存储区域的起始位置的差值。第一全局写指针指向第一存储区域的第一字节。
在第三方面的一种可选方式中,处理器还用于获取第一存储区域的第一读标识。第一读标识表征第一存储区域中已被读取的数据的空间大小。处理器还用于确定第一写标识和第一读标识的大小关系;第一条件还包括:第一写标识大于第一读标识。
在第三方面的一种可选方式中,第一子区域和第一数据的大小为X字节。X为大于0的整数。处理器还用于通过X更新第一存储区域的第一读标识。更新后的第一读标识等于第一读标识和X之和。
在第三方面的一种可选方式中,处理器还用于获取循环存储队列的第二全局写指针。 第二全局写指针指向第一存储区域中的第二字节。第二字节为第一子区域的起始位置。处理器还用于若第二字节的位置与第一存储区域的终点位置的差值大于或等于X,则在第一子区域中写入第一数据。
在第三方面的一种可选方式中,处理器还用于获取循环存储队列的第三全局写指针。第三全局写指针指向第一存储区域的第三字节。处理器还用于获取待写入的第二数据的大小。第二数据的大小为N字节。处理器还用于若第三字节的位置与第一存储区域的终点位置表征第一存储区域的剩余区域小于N字节,则为剩余区域添加目标标识。目标标识用于表征剩余区域为无效子区域。
在第三方面的一种可选方式中,处理器还用于确定第一子区域是否为无效子区域。第一条件还包括:第一子区域不是无效子区域。
在第三方面的一种可选方式中,处理器还用于若满足第二条件,则更新第三全局写指针。更新后的第三全局写指针指向第二存储区域的第一个字节。第二存储区域为第一存储区域的下一个存储区域。第二条件包括:第二存储区域未分配过,或第三全局读指针指向第二存储区域以外的存储区域。第二存储区域的第二写标识除以第二存储区域的总的空间大小等于整数。第二写标识表征第二存储区域中已存储数据的空间大小。
在第三方面的一种可选方式中,处理器还用于将第二写标识清零。第一全局读指针包括第一读区域指针和第一区域内读偏移指针。第一读区域指针指向第一存储区域。第一区域内读偏移指针指向第一存储区域中的第二字节。第一全局写指针包括第一写区域指针和第一区域内写偏移指针。处理器还用于若第一读区域指针和第一写区域指针的差值大于M,则将第一存储区域中的第一读标识清零。
在第三方面的一种可选方式中,处理器还用于若第一读区域指针和第一写区域指针的差值大于M,则更新第一读区域指针。更新后的第一读区域指针等于第一写区域指针和Z的差值。Z=M-1。
在第三方面的一种可选方式中,第二条件还包括:第二存储区域的第二读标识除以第二存储区域的总的空间大小等于整数。第二读标识表征第二存储区域中已被读取的数据的数据大小。
本申请第四方面提供了一种计算机存储介质,其特征在于,所述计算机存储介质中存储有指令,所述指令在计算机设备上执行时,使得所述计算机设备执行如第一方面或第一方面任意一种实施方式所述的方法。
本申请第五方面提供了一种计算机程序产品,其特征在于,所述计算机程序产品在计算机设备上执行时,使得所述计算机设备执行如第一方面或第一方面任意一种实施方式所述的方法。
附图说明
图1为循环存储队列的结构示意图;
图2为本申请中提供的数据处理方法的流程示意图;
图3为本申请中提供的循环存储队列的第一个结构示意图;
图4为本申请中提供的写入数据的方法的第一个流程示意图;
图5为本申请中提供的循环存储队列的第二个结构示意图;
图6为本申请中提供的全局写指针的结构示意图;
图7为本申请中提供的读取数据的方法的第一个流程示意图;
图8为本申请中提供的写入数据的方法的第二个流程示意图;
图9为本申请中提供的读取数据的方法的第二个流程示意图;
图10为本申请中提供的数据处理装置的结构示意图;
图11为本申请中提供的计算机设备的结构示意图。
具体实施方式
本申请提供了一种数据处理方法、数据处理装置以及相关设备。在申请中,通过增加第一写标识,使得乱序commit不会影响读取的数据的正确性。因此,本申请可以通过乱序commit提高***的运行效率。应理解,本申请中使用的“第一”、“第二”、“目标”等仅用于区分描述的目的,而不能理解为指示或暗示相对重要性,也不能理解为指示或暗示顺序。另外,为了简明和清楚,本申请多个附图中重复参考编号和/或字母。重复并不表明各种实施例和/或配置之间存在严格的限定关系。
本申请中的数据处理方法可以应用于计算机领域,例如使用循环存储队列的操作***。在图1所示的循环存储队列中,不同的线程必须按照特定的顺序执行commit操作,简称顺序commit。特定的顺序是指全局写指针和全局读指针的移动方向。例如,在图1中,特定的顺序为逆时针方向。在采用顺序commit时,在后的线程即使先写入数据,也必须等待在前的线程完成commit操作。并且,在等待期间,在后的线程需要频繁判断在前的线程是否完成commit操作,从而降低了***的运行效率。
为此,本申请提供了一种数据处理方法。图2为本申请中提供的数据处理方法的第一个流程示意图。如图2所示,数据处理方法包括以下步骤。
在步骤201中,计算机设备获取循环存储队列的第一全局读指针。第一全局读指针指向第一存储区域中的第一子区域。
本申请中的数据处理方法采用了另一种循环存储队列。具体地,循环存储队列分为逻辑上的M个存储区域。M为大于1的整数。每个存储区域在逻辑上连续。每个存储区域对应一个写标识。写标识表征对应的存储区域中已存储的数据的数据大小。例如,图3为本申请中提供的循环存储队列的第一个结构示意图。如图3所示,循环存储队列包括三个存储区域。三个存储区域的空间大小可以相同,也可以不同。三个存储区域分别为存储区域301、存储区域302和存储区域303。三个存储区域对应三个写标识。三个存储区域和三个写标识一一对应。
循环存储队列还包括对应的全局写指针和全局读指针。随着数据的写入和读取,全局写指针和全局读指针的位置沿逻辑方向不断变化。在图3中,逻辑方向为逆时针方向。应理解,在实际应用中,逻辑方向还可以是顺时针方向。循环存储队列是逻辑上的环状空间。因此。全局写指针或全局读指针可以循环的经过相同的区域。根据前面的描述可知,在时域上,全局写指针和全局读指针的位置可能不断发生变化。因此,为了方便描述,在本申请中,不同时刻的全局写指针和全局读指针可能拥有不同的称呼。例如,不同的称呼包括 第一全局写指针、第一全局读指针、第二全局写指针、第二全局读指针等。
计算机设备获取循环存储队列的第一全局读指针。第一全局读指针指向第一存储区域中的第一子区域。具体地,第一全局读指针可以指向第一子区域的起始位置。起始位置可以是第一子区域的第一个字节。第一存储区域为M个存储区域中的一个存储区域。在写入数据的过程中,计算机设备以子区域为单位写入数据。例如,存储区域301的总的空间大小为100字节。计算机设备将前40个字节分配给了线程1。计算机设备将后60个字节分配给了线程2。线程1在前40个字节中写入数据。线程2在后60个字节写入数据。此时,前40个字节和后60个字节属于不同的子区域。每个存储区域可以包括一个或多个子区域。第一子区域为一个或多个子区域中任意一个子区域。
在步骤202中,计算机设备获取第一存储区域的第一写标识。
根据前面的描述可知,每个存储区域对应一个写标识。第一存储区域对应第一写标识。第一写标识表征第一存储区域中已存储数据的空间大小。应理解,在本申请中,第一存储区域中已存储数据的空间大小只包括计算机设备在最后一次循环中写入的数据的数据大小。具体地,随着数据的写入,计算机设备循环的分配第一存储区域的存储空间。例如,在第一次循环中,计算机设备将第一存储区域分配给了线程1和线程2。在第二次循环中,计算机设备将第一存储区域分配给了线程1、线程3和线程4。在最后一次循环中,计算机设备将第一存储区域分配给了一个或多个线程。在分配到存储空间中,一个或多个线程在第一存储区域中写入数据。第一写标识用于表征最后一次循环中,一个或多个线程在第一存储区域中写入的数据的数据大小。其中,第一写标识的值是随着线程的commit操作而改变的。例如,第一存储区域包括第一子区域和第二子区域。第一子区域包括40字节。第二子区域包括60字节。在线程1和线程2未写入数据时,第一写标识的值可以是0或100的倍数。假设第一写标识的值是0。线程1在第一子区域写入数据后,线程1执行commit操作。此时,第一写标识变为40。线程1在第二子区域写入数据后,线程2执行commit操作。此时,第二写标识变为100。
在步骤203中,若第一写标识表征的第一存储区域中已存储数据的空间大小等于第一存储区域中已被分配的空间大小,则计算机设备读取第一子区域中的第一数据。
通过第一写标识,计算机设备可以确定第一存储区域的commit状态。commit状态包括完全commit和未完全commit。完全commit表示第一存储区域中已存储数据的空间大小等于已被分配的空间大小。未完全commit表征第一存储区域中已存储数据的空间大小小于已被分配的空间大小。在第一存储区域写入数据前,计算机设备需要将第一存储区域中的存储空间分配给一个或多个线程。根据前面的描述可知,计算机设备循环的在第一存储区域中写入数据。因此,计算机设备循环的将第一存储空间中的存储空间分配给线程。应理解,在本申请中,第一存储区域中已被分配的空间大小只包括计算机设备在最后一次循环中分配的空间大小。
在申请中,第一写标识表征的是已存储数据的空间大小。若已存储数据的空间大小等于已被分配的空间大小,则计算机设备读取第一子区域中的第一数据。第一子区域和第一数据的大小为X字节。X为大于0的整数。若已存储数据的空间大小小于已被分配的空间大小时,则计算机设备不读取第一子区域中的数据。例如,假设第一存储区域中已被分配 的空间大小为100字节。其中,线程1分配到了前40个字节。线程2分配到了后60个字节。第一子区域为前40个字节。在线程2执行commit操作后,后60个字节变为已存储数据的空间。此时,已被分配的空间大小不等于已存储数据的空间大小。计算机设备不读取第一子区域中的数据。在线程1执行commit操作后,前40个字节变为已存储数据的空间。此时,已被分配的空间大小为100字节。已被分配的空间大小等于已存储数据的空间大小。计算机设备读取第一子区域中的数据。因此,在第一存储区域中,乱序commit并不会影响对commit状态的判断,即乱序commit不会影响读取的数据的正确性。因此,线程2在第一存储区域中写入数据后,线程2可以不需要等待线程1完成commit操作,从而提高了***的运行效率。
在实际应用中,计算机设备可以通过第一全局写指针确定第一存储区域中已被分配的空间大小。具体地,若第一全局写指针指向第一存储区域以外的存储区域,则计算机设备确定第一存储区域中已被分配的空间大小等于第一存储区域总的空间大小。若第一全局写指针指向第一存储区域中的第二子区域,则计算机设备确定第一存储区域中已被分配的空间大小等于第二子区域的起始位置和第一存储区域的起始位置的差值。例如,第一存储区域包括200个字节。第二子区域的起始位置为200个字节中的第101个字节。此时,计算机设备确定已被分配的空间大小为100字节。
根据前面的描述可知,循环存储队列中的每个存储区域对应一个写标识。写标识用于表征对应的存储区域中已存储数据的空间大小。在实际应用中,每个存储区域还可以对应一个读标识。读标识用于表征对应的存储区域中已被读取的数据的数据大小。例如,第一读标识用于表征第一存储区域中已被读取的数据的数据大小。根据前面的描述可知,全局读指针沿逻辑方向不断移动。因此,全局读指针可以循环的经过同一个存储区域,即计算机设备循环的在同一个存储区域中读取数据。应理解,在本申请中,第一存储区域中已被读取的数据的数据大小只包括计算机设备在最后一次循环中读取的数据的数据大小。
在计算机设备执行前述步骤203之前,计算机设备可以确定第一写标识和第一读标识的大小关系。当第一写标识等于第一读标识时,表征第一存储区域中已被读取的数据的数据大小等于已存储数据的空间大小。此时,第一子区域中还未写入数据。因此,计算机设备无需执行步骤203。当第一写标识小于第一读标识时,表征第一存储区域中已被读取的数据的数据大小小于已存储数据的空间大小,此时,第一子区域中已写入数据。因此,计算机设备执行步骤203。
根据前面的描述可知,第一读标识用于表征第一存储区域中已被读取的数据的数据大小。因此,在读取第一子区域中的数据后,计算机设备可以更新第一读标识。更新后的第一读标识等于第一读标识和X之和。X为第一数据的数据大小。或X为第一子区域的空间大小。
在循环存储队列中,计算机设备以子区域为单位写入和读取数据。例如,在前面的描述中,计算机设备在第一子区域中读取第一数据。因此,在计算机设备在读取第一数据前,计算机设备还在第一子区域中写入第一数据。具体地,计算机设备获取循环存储队列的第二全局写指针。第二全局写指针指向第一存储区域中的第二字节。其中,第二字节为第一子区域的起始位置。应理解,在写入数据时,计算机设备可以根据第一数据的数据大小灵 活调整子区域的空间大小。因此,在不同的循环中,每个存储区域中的子区域的数量和空间大小可能是不同的。
若第二字节的位置与第一存储区域的终点位置的差值大于或等于X,则表征第一存储区域中的剩余空间大于第一数据的数据大小。因此,计算机设备从第二字节开始写入第一数据。若第二字节的位置与第一存储区域的终点位置的差值小于X,则表征第一存储区域中的剩余空间小于第一数据的数据大小。计算机设备无法在剩余空间中写入第一数据。
当剩余空间不足时,计算机设备可以为剩余空间添加目标标识。在读取数据前,计算机设备根据目标标识确定是否读取剩余空间中的数据。具体地,图4为本申请中提供的写入数据的方法的第一个流程示意图。其中,本申请中的数据处理方法可以应用于循环存储队列中的数据写入和读取。为了方便描述,本申请将数据处理方法分为写入数据的方法和读取数据的方法。写入数据的方法和读取数据的方法存在一定的关联性。因此,两个方法中的描述可以互相参考。如图4所示,写入数据的方法包括以下步骤。
在步骤401中,计算机设备获取当前全局写指针,根据当前全局写指针确定当前存储区域。循环存储队列的描述可以参考前述图2或图3的相关描述。计算机设备获取循环存储队列当前的全局写指针。当前的全局写指针也称为当前全局写指针。当前全局写指针指向M个存储区域中的当前存储区域。计算机设备可以从循环存储队列的队列头部中获取当前全局写指针。具体地,图5为本申请中提供的循环存储队列的第二个结构示意图。如图5所示,循环存储队列包括3个存储区域。3个存储区域分别为存储区域301、存储区域302和存储区域303。存储区域301包括子区域a1、子区域b1、子区域b2和目标无效子区域502。存储区域302包括子区域b4、子区域b5和剩余空间a2。其中,剩余空间a2可能会被计算机设备分配一个或多个线程。因此,剩余空间a2可能形成多个子区域。存储区域303包括子区域a3、子区域a4和目标无效子区域504。循环存储队列还包括队列头部500。队列头部500可以用于存储全局写指针和全局读指针。在图5中,全局写指针指向存储区域302中的子区域a2。全局读指针指向存储区域301中的子区域b1。
每个存储区域还可以包括对应的区域头部。区域头部用于存储对应的存储区域的读标识和/或写标识。例如,存储区域301包括区域头部501。区域头部501用于存储存储区域301的写标识和/或读标识。类似地,存储区域302包括区域头部503。存储区域303包括区域头部505。
每个存储区域还可以包括对应的初始无效子区域(图中未示出)。当存储区域的空间被完全分配后,全局写指针会指向初始无效子区域。当存储区域的空间被不完全分配后,计算机设备存储区域的剩余区域和初始无效子区域合并,得到无效子区域。例如,存储区域301包括100字节。初始无效子区域包括2字节。若存储区域301的100字节被完全分配,则全局写指针会指向存储区域301的初始无效子区域。计算机设备将初始无效子区域作为无效子区域。当存储区域301的空间被不完全分配后,全局写指针会指向存储区域301的剩余空间。若剩余空间小于将要写入的数据大小,则计算机设备将剩余空间作为目标无效子区域。计算机设备将目标无效子区域和初始无效子区域合并,得到无效子区域。例如,若存储区域301的100字节被不完全分配后,剩余空间包括10字节。10字节的剩余空间小于当前数据(将要写入的数据)的数据大小,则计算机设备可以将10字节作为目标无效 子区域。计算机设备将目标无效子区域和初始无效子区域合并,得到无效子区域。此时,无效子区域包括12字节。
在步骤402中,计算机设备根据当前全局写指针和当前数据大小确定当前存储区域是否有足够剩余空间。其中,当前数据大小是当前线程将要写入的当前数据的数据大小。当前全局写指针指向当前存储区域中的当前字节。若当前存储区域的终点位置和当前字节的差值小于当前数据大小,则表征当前存储区域没有足够的剩余空间。若当前存储区域的终点位置和当前字节的差值大于或等于当前数据的数据大小,则表征当前存储区域有足够的剩余空间。若有足够的剩余空间,则计算机设备执行步骤403。若没有足够的剩余空间,则计算机设备执行步骤406。
在步骤403中,计算机设备确定是否抢头成功。其中,在多线程并发的场景,可能存储多个线程竞争写入数据。只有在当前线程抢头成功后,计算机设备才可以从当前字节开始写入当前数据。若当前线程抢头成功,则计算机设备执行步骤404。若抢头成功,则表征计算机设备更新了当前全局写指针。更新后的当前全局写指针指向当前字节的后X个字节。X个当前数据大小。具体地,计算机设备可以通过原子操作更新当前全局写指针。例如,计算机设备可以通过比较并交换(compare and swap,CAS)技术更新当前全局写指针。类似地,在本申请后续更新全局写指针或全局读指针的操作中,计算机设备都可以通过原子操作更新全局写指针或全局读指针。若当前线程抢头失败,则计算机设备执行步骤401。其中,若当前线程抢头失败,则其他线程已经修改了当前全局写指针。因此,计算机设备需要重新执行步骤401。
在步骤404中,计算机设备执行写流程。在抢头成功后,计算机设备在从当前字节开始写入当前数据。当前数据的数据大小为X字节。
在步骤405中,计算机设备更新当前存储空间的当前写标识。根据前面的描述可知,M个存储区域和M个写标识一一对应。当前写标识对应当前存储区域。当前写标识表征当前存储区域已存储的数据的数据大小。计算机设备在当前存储区域中写入当前数据后,计算机设备更新当前写标识。更新后的当前写标识等于当前写标识加X的和。
根据前面的描述可知,计算机设备循环的在当前存储区域中写入数据。因此,当前写标识的值可以不断增大。为了节约存放当前写标识的空间,计算机设备也可以不断对当前写标识进行清零。具体地,在当前写标识的值等于当前存储区域总的空间大小时,计算机设备对当前写标识清零。例如,当前存储区域总的空间大小为100字节。当当前写标识的值等于100时,计算机设备将当前写标识的值设为0。
在步骤406中,计算机设备确定剩余空间是否为无效子区域。计算机设备可以通过目标标识确定剩余空间是否为无效子区域。
例如,目标标识是剩余空间中的比特位全为1。若剩余空间中的比特位全为1,则计算机设备确定剩余空间是无效子区域。若剩余空间中的比特位不全为1,则计算机设备确定剩余空间不是无效子区域。
例如,目标标识是剩余空间的头部中的标识。具体地,对于每个子区域,计算机设备设定一个对应的头部。在计算机设备确定没有足够的剩余空间后,计算机设备将剩余空间作为目标无效子区域。计算机设备在目标无效子区域的头部添加目标标识。目标标识的具 体内容可以是某个比特位的值。例如,比特位的值是1时,表征剩余空间是无效子区域。比特位的值是0时,表征剩余空间不是无效子区域。若剩余空间不是无效子区域,则执行步骤407。若剩余空间是无效子区域,则执行步骤408。关于无效子区域的描述,可以参考前述步骤401中的描述。
根据前面的描述可知,若当前存储区域的内存空间被完全分配,则当前全局写指针可能指向当前存储区域对应的初始无效子区域。此时,当前存储区域没有足够的剩余空间。计算机设备确定初始无效子区域为无效子区域。计算机设备执行步骤408。
在步骤407中,计算机设备将剩余空间作为无效子区域。若当前存储区域包括初始无效子区域,则计算机设备将剩余空间和初始无效子区域合并,得到无效子区域。若当前存储区域不包括初始无效子区域,则计算机设备将剩余空间作为无效子区域。若剩余空间没有目标标识,则计算机设备为剩余空间添加目标标识。关于目标标识的描述参考前述步骤406中的描述。
在步骤408中,计算机设备根据当前全局写指针计算下一个存储区域的全局写指针。下一个存储区域是当前存储区域沿逻辑方向上的下一个存储区域。在剩余空间有目标标识时,计算机设备根据当前全局写指针计算下一个存储区域的全局写指针。下一个存储区域的全局写指针指向下一个存储区域。例如,下一个存储区域的全局写指针指向下一个存储区域的起始位置。应理解,此时,计算机设备并未修改当前全局写指针。
在步骤409中,计算机设备根据下一个存储区域的全局写指针确定下一个存储区域是否被分配过。具体地,根据下一个存储区域的全局写指针的格式不同,计算机设备可以有不同的方式确定下一个存储区域是否被分配过。
例如,下一个存储区域的全局写指针记录循环存储队列总的被分配过的空间大小。此时,若下一个存储区域的全局写指针大于循环存储队列总的空间大小,则计算机设备确定下一个存储区域被分配过。若下一个存储区域的全局写指针小于或等于循环存储队列总的空间大小,则计算机设备确定下一个存储区域未被分配过。例如,循环存储队列包括10个存储区域。每个存储区域包括100个字节。经过每一次循环后,计算机设备不对全局写指针清零。此时,若下一个存储区域的全局写指针大于1000,则计算机设备确定下一个存储区域被分配过。若下一个存储区域的全局写指针小于1000,则计算机设备确定下一个存储区域未被分配过。
例如,图6为本申请中提供的全局写指针的结构示意图。如图6所示,当前全局写指针包括当前写区域指针601和当前区域内写偏移指针602。当前写区域指针601用于表征当前存储区域。假设循环存储队列包括10个存储区域。计算机设备从10个存储区域中的第一个存储区域开始写入数据。当当前写区域指针601为1时,表征当前存储区域为10个存储区域中的第一个存储区域。当当前写区域指针601为2时,表征当前存储区域为10个存储区域中的第二个存储区域。若计算机设备不对当前写区域指针清零,则随着循环的增加,当前写区域指针601会大于10。例如,当当前写区域指针601为11时,表征当前存储区域为10个存储区域中的第一个存储区域。当当前写区域指针601为12时,表征当前存储区域为10个存储区域中的第二个存储区域。下一个存储区域的全局写指针简称为下一个全局写指针。若下一个全局写指针的写区域指针大于存储区域的个数M,则计算机设备确 定下一个存储区域被分配过。若下一个全局写指针的写区域指针小于或等于存储区域的个数M,则计算机设备确定下一个存储区域未被分配过。若下一个存储区域被分配过,则计算机设备执行步骤410。若下一个存储区域未被分配过,则计算机设备执行步骤412。
当前区域内写偏移指针602用于表征当前字节对当前存储区域的起始位置的偏移量。假设当前存储区域包括100个字节。100个字节按照逻辑方向排序。当当前区域内写偏移指针602等于5时,表征当前字节为100个字节中的第五个字节。当当前区域内写偏移指针602等于6时,表征当前字节为100个字节中的第六个字节。若计算机设备不对当前区域内写偏移指针602清零,则随着循环的增加,当前区域内写偏移指针602会大于100。例如,当当前区域内写偏移指针602等于105时,表征当前字节为100个字节中的第五个字节。在其中的一个示例中,当前全局写指针包括64位比特。当前写区域指针601包括64位比特中的前48位比特。当前区域内写偏移指针602包括64位比特中的后16位比特。
在步骤410中,计算机设备确定下一个存储区域是否被完全写入。根据前述对循环存储队列的描述可知,每个存储区域对应一个写标识。因此,下一个存储区域对应下一个写标识。计算机设备可以获取下一个写标识。下一个写标识表征最后一个循环中已存入的数据的数据大小。例如,假设下一个存储区域包括100个字节。当下一个写标识等于40时,表征下一个存储区在最后一个循环中已存入的数据的数据大小为40字节。应理解,若计算机设备不对下一个写标识清零,则随着循环的增加,下一个写标识的值会大于下一个存储区域的总的空间大小。例如,当下一个写标识等于140时,表征下一个存储区在最后一个循环中已存入数据的为40字节。
若下一个写标识除以下一个存储区域的总的空间大小等于整数,则计算机设备确定下一个存储区域被完全写入。例如,下一个存储区域的总的空间大小为100字节。当下一个写标识等于200时,计算机设备确定下一个存储区域被完全写入。若下一个写标识除以下一个存储区域的总的空间大小不等于整数,则计算机设备确定下一个存储区域未被完全写入。例如,下一个存储区域的总的空间大小为100字节。当下一个写标识等于205时,计算机设备确定下一个存储区域未被完全写入。若下一个存储区域未被完全写入,则计算机设备执行步骤411。若下一个存储区域被完全写入,则计算机设备执行步骤412。
其中,在最后一次循环后,若100个字节被分配出去后,100个字节都未被执行commit操作。此时,下一个存储区域未被完全写入。但是下一个写标识除以下一个存储区域的总的空间大小仍可能等于整数。因此,为了避免这种情况的发生,计算机设备可以获取当前全局读指针。若当前全局读指针指向下一个存储区域以外的存储区域,下一个写标识除以下一个存储区域的总的空间大小等于整数,则计算机设备确定下一个存储区域被完全写入。若当前全局读指针指向下一个存储区域,或下一个存储区域写标识除以下一个存储区域存储区域的总的空间大小不等于整数,则计算机设备确定下一个存储区域未被完全写入。
在步骤411中,结束。其中,结束可以是指计算机设备中的当前线程放弃存储当前数据,或者计算机设备中的当前线程回到步骤401。
在步骤412中,计算机设备确定当前全局写指针是否被修改。在前述步骤401中,计算机设备获取了当前全局写指针。在多线程并发的场景中,可能存在其它线程已经修改了当前全局写指针。例如存在其它线程完成了后续的步骤414。因此,计算机设备在此处再 次获取当前全局写指针。若两次获取的当前全局写指针相同,则计算机设备确定当前全局写指针未被修改。若两次获取的当前全局写指针不同,则计算机设备确定当前全局写指针未被修改。若当前全局写指针未被修改,则执行步骤413。若当前全局写指针被修改,则执行步骤401。
在步骤413中,计算机设备将下一个存储区域的写标识清零。下一个存储区域对应下一个写标识。
在步骤414中,计算机设备将下一个存储区域的全局写指针作为当前全局写指针。
应理解,为了方便描述,在图4中的流程图中,采用了当前全局写指针、当前写标识、当前存储区域和当前全局读指针等描述。在实际应用中,可以将“当前”修改为“第一”、“第二”或“第三”等描述。例如,当前全局写指针可以为第一全局写指针、第二全局写指针或第三全局写指针等。例如,当前存储区域可以为第一存储区域或第二存储区域等。
前面对本申请中的写入数据的方法进行描述。下面对本申请中读取数据的方法进行描述。具体地,图7为本申请中提供的读取数据的方法的第一个流程示意图。如图7所示,写入数据包括以下步骤。
在步骤701中,计算机设备获取当前全局读指针,根据当前全局读指针确定当前存储区域。循环存储队列的描述可以参考前述图2至图4中的相关描述。计算机设备的当前线程获取循环存储队列当前的全局读指针。当前的全局读指针也称为当前全局读指针。当前全局读指针指向M个存储区域中的当前存储区域的当前子区域。例如,当前全局读指针指向当前子区域的起始位置。起始位置为当前字节。计算机设备可以从循环存储队列的队列头部中获取当前全局读指针。
在步骤702中,计算机设备确定当前存储区域是否被覆盖写。根据前述图4的描述可知,当前全局写指针包括当前写区域指针和当前区域内写偏移指针。类似的,当前全局读指针也可以包括当前读区域指针和当前区域内读偏移指针。当前读区域指针用于表征当前存储区域。当前区域内读偏移指针用于表征当前字节对当前存储区域的起始位置的偏移量。关于当前读区域指针和当前区域内读偏移指针的描述,可以参考前述当前写区域指针和当前区域内写偏移指针的相关描述。应理解,当前全局写指针指向的当前存储区域和当前全局读指针指向的当前存储区域可以是一个存储区域,也可以不是同一个区域。若当前写区域指针和当前读区域指针的差值大于M,则计算机设备确定当前存储区域被覆盖写。若当前写区域指针和当前读区域指针的差值小于或等于M,则计算机设备确定当前存储区域未被覆盖写。若当前存储区域未被覆盖写,则执行步骤704。若当前存储区域被覆盖写,则执行步骤703。
在步骤703中,计算机设备将当前读标识清零。计算机设备更新当前全局读指针。
当前存储区域对应当前写标识和当前读标识。为了提高写入数据的效率,计算机设备在写入数据时,可能会覆盖还未被读取的数据。此时,计算机设备的当前读标识无法被正常更新。计算机设备无法通过后续的步骤704确定是否执行步骤706。因此,在前述图4的步骤413中,计算机设备将当前写标识清零。在此步骤中,计算机设备将当前读标识清零。
若当前读区域指针和当前写区域指针的差值大于M,则表征当前存储区域被覆盖写。 若计算机设备仍然从当前字节开始读取数据,则会丢失当前全局写指针到当前字节之间的数据。为此,计算机设备更新当前全局读指针。更新后的当前读区域指针等于当前写区域指针和Z的差值。其中,Z=M-1。
在步骤704中,计算机设备确定当前写标识是否大于当前读标识。若当前写标识大于当前读标识,则表征当前子区域已经被写入未被读取的数据,计算机设备可以读取当前子区域中的数据。若当前写标识小于或等于当前读标识,则表征当前子区域未被写入未被读取的数据,计算机设备无法读取当前子区域中的数据。因此,若当前写标识等于当前读标识,则计算机设备执行步骤705。若当前写标识大于当前读标识,则计算机设备执行步骤706。
在步骤705中,结束。其中,结束可以是指计算机设备中的当前线程放弃存储当前数据,或者计算机设备中的当前线程回到步骤701。
在步骤706中,计算机设备确定当前全局写指针是否指向当前存储区域。其中,关于当前全局写指针的描述可以参考前述图4中的当前全局写指针的描述。例如,当前全局写指针包括当前写区域指针和当前区域内写偏移指针。假设循环存储队列包括10个存储区域。当前存储区域为10个存储区域中的第一个存储区域。当当前写区域指针除以10的余数等于1时,表征当前全局写指针指向当前存储区域。例如,当前写区域指针等于1、11或21等。当当前写区域指针除以10的余数不等于1时,表征当前全局写指针不指向当前存储区域。例如,当前写区域指针等于3、4或23等。当当前全局写指针指向当前存储区域时,计算机设备执行步骤707。当当前全局写指针不指向当前存储区域时,计算机设备执行步骤709。
在步骤707中,计算机设备确定当前全局写指针中的当前区域内写偏移指针是否等于当前写标识。若当前区域内写偏移指针不等于当前写标识,则表征当前存储区域的commit状态为未完全commit。若当前区域内写偏移指针等于当前写标识,则表征当前存储区域的commit状态为完全commit。关于commit状态的描述可以参考前述图2中的相关描述。因此,若当前区域内写偏移指针不等于当前写标识,则计算机设备执行步骤708。若当前区域内写偏移指针等于当前写标识,则计算机设备执行步骤710。其中,当前区域内写偏移指针指向当前存储区域中第一字节。第一字节为当前存储区域中除了当前字节以外的任意一个字节。
在步骤708中,结束。其中,结束可以是指计算机设备中的当前线程放弃存储当前数据,或者计算机设备中的当前线程回到步骤701。
在步骤709中,计算机设备确定当前存储区域是否被完全写入。若当前写标识除以当前存储区域的总的空间大小等于整数,则计算机设备确定当前存储区域被完全写入。例如,当前存储区域的总的空间大小为100字节。当当前写标识等于200时,计算机设备确定当前存储区域被完全写入。若当前写标识除以当前存储区域的总的空间大小不等于整数,则计算机设备确定当前存储区域未被完全写入。例如,当前存储区域的总的空间大小为100字节。当当前写标识等于205时,计算机设备确定当前存储区域未被完全写入。若当前存储区域未被完全写入,则表征在最后一个循环中,当前存储区域中存在空间未被执行commit操作。若当前存储区域被完全写入,则表征在最后一个循环中,当前存储区域中的在所有 空间都被执行了commit操作。因此,若当前存储区域未被完全写入,则计算机设备执行步骤705。若当前存储区域被完全写入,则计算机设备执行步骤710。
在步骤710中,计算机设备确定当前子区域是否属于无效子区域。根据前面的描述可知,当前全局读指针指向当前子区域。若当前子区域不属于无效子区域,则计算机设备执行步骤711。若当前子区域属于无效子区域,则执行步骤712。关于无效子区域的描述,可以参考前述图4中的相关描述。例如,计算机设备可以通过目标标识确定当前子区域是否为属于无效子区域。若当前子区域包括对应的目标标识,则计算机设备确定当前子区域属于无效子区域。若当前子区域不包括对应的目标标识,则计算机设备确定当前子区域不属于无效子区域。
在步骤711中,计算机设备读取当前子区域中的当前数据。
在步骤712中,计算机设备确定当前存储区域是否被覆盖写。若当前全局写指针移动,则当前存储区域可能被覆盖写。因此,计算机设备再次确定当前存储区域是否被覆盖写。具体地,计算机设备获取当前写区域指针和当前写区域指针。若当前写区域指针和当前读区域指针的差值大于M,则计算机设备确定当前存储区域被覆盖写。若当前写区域指针和当前读区域指针的差值小于或等于M,则计算机设备确定当前存储区域未被覆盖写。若当前存储区域未被覆盖写,则计算机设备执行步骤713。若当前存储区域被覆盖写,则计算机设备执行步骤703。
在步骤713中,计算机设备确定当前子区域是否属于无效子区域。若当前子区域属于无效子区域,则执行步骤715。若当前子区域不属于无效子区域,则执行步骤714。
在步骤714中,计算机设备更新全局读指针和当前读标识。更新后的当前全局读指针指向当前子区域的下一个子区域。更新后的当前读标识等于当前读标识和X的和。其中,X为计算机设备读取的当前数据的数据大小。
在步骤715中,计算机设备确定当前写区域指针是否大于当前读区域指针。若当前写区域指针大于当前读区域指针,则计算机设备执行步骤717。若当前写区域指针小于或等于当前读区域指针,则计算机设备执行步骤716。
在步骤716中,结束。其中,结束可以是指计算机设备中的当前线程放弃存储当前数据,或者计算机设备中的当前线程回到步骤701。
在步骤717中,计算机设备更新当前全局读指针。计算机设备将当前读标识清零。更新后的当前全局读指针指向当前存储区域的下一个存储区域。具体地,更新后的当前全局读指针指向下一个存储区域的第一个子区域。
应理解,为了方便描述,在图7中的流程图中,采用了当前全局写指针、当前写标识、当前存储区域和当前全局读指针等描述。在实际应用中,可以将“当前”修改为“第一”、“第二”或“第三”等描述。例如,当前全局读指针可以为第一全局读指针、第二全局读指针等。例如,当前存储区域可以为第一存储区域或第二存储区域等。
应理解,在前述图4的描述中,当前全局写指针对应当前存储区域。在前述图7的描述中,当前全局读指针对应当前存储区域。两个当前存储区域可以是同一个存储区域,也可以不是同一个存储区域。
应理解,前述图4为写入数据的方法的流程图,图7为读取数据的方法的流程图。在 循环存储队列中,写入数据和读取数据是相互关联的。因此,关于关于图7中的描述,可以参考图4中的描述。关于图4中的描述,可以参考图7中的描述。
在实际应用中,每个存储区域还可以包括对应的写区域标识和读区域标识。例如,当前存储区域对应当前写区域标识和当前读区域标识。当前写区域标识等于当前写区域指针。当前写区域标识和当前写标识可以记录在一个字段中。例如,一个字段包括64比特。当前写区域标识包括64比特中的前48比特。当前写标识包括64比特中的后16比特。类似地,当前读区域标识等于当前读区域指针。当前读区域标识和当前读标识可以记录在一个字段中。例如,一个字段包括64比特。当前读区域标识包括64比特中的前48比特。当前读标识包括64比特中的后16比特。当前写区域标识和当前读区域标识可以用于避免CAS中的ABA问题。
在图4的写入数据的方法中,计算机设备可能覆盖未被读取的数据,造成数据丢失。在某些场景中,丢失数据可能造成严重的后果。为此,本申请提供了另一个写入数据的方法。在该方法中,计算机设备不覆盖未被读取的数据。具体地,图8为本申请中提供的写入数据的方法的第二个流程示意图。如图8所示,写入数据包括以下步骤。
在步骤801中,计算机设备获取当前全局写指针,根据当前全局写指针确定当前存储区域。
在步骤802中,计算机设备根据当前全局写指针和当前数据大小确定当前存储区域是否有足够剩余空间。若有足够的剩余空间,则计算机设备执行步骤803。若没有足够的剩余空间,则计算机设备执行步骤806。
在步骤803中,计算机设备确定是否抢头成功。若抢头成功,则计算机设备执行步骤804。若抢头失败,则计算机设备执行步骤801。
在步骤804中,计算机设备执行写流程。
在步骤805中,计算机设备更新当前存储空间的当前写标识。
在步骤806中,计算机设备确定剩余空间是否为无效子区域。若剩余空间不是无效子区域,则执行步骤807。若剩余空间是无效子区域,则执行步骤808。
在步骤807中,计算机设备将剩余空间作为无效子区域。
在步骤808中,计算机设备根据当前全局写指针计算下一个存储区域的全局写指针。
在步骤809中,计算机设备根据下一个存储区域的全局写指针确定下一个存储区域是否被分配过。若下一个存储区域被分配过,则计算机设备执行步骤810。若下一个存储区域未被分配过,则计算机设备执行步骤812。
在步骤810中,计算机设备确定下一个存储区域是否被完全写入。若下一个存储区域未被完全写入,则计算机设备执行步骤811。若下一个存储区域被完全写入,则计算机设备执行步骤812。
在步骤811中,结束。
在步骤812中,计算机设备确定下一个存储区域是否被完全读取。根据前述对循环存储队列的描述可知,每个存储区域对应一个读标识。因此,下一个存储区域对应下一个读标识。计算机设备可以获取下一个读标识。下一个读标识表征最后一次循环中在下一个存储区域中已读取数据的数据大小。例如,假设下一个存储区域包括100个字节。当下一个 读标识等于40时,表征下一个存储区在最后一个循环中已读取数据的数据大小为40字节。应理解,若计算机设备不对下一个读标识清零,则随着循环的增加,下一个读标识的值会大于下一个存储区域的总的空间大小。例如,当下一个读标识等于140时,表征下一个存储区在最后一个循环中已读取数据的数据大小为40字节。
若下一个读标识除以下一个存储区域的总的空间大小等于整数,则计算机设备确定下一个存储区域被完全读取。例如,下一个存储区域的总的空间大小为100字节。当下一个读标识等于200时,计算机设备确定下一个存储区域被完全读取。若下一个读标识除以下一个存储区域的总的空间大小不等于整数,则计算机设备确定下一个存储区域未被完全读取。例如,下一个存储区域的总的空间大小为100字节。当下一个读标识等于205时,计算机设备确定下一个存储区域未被完全读取。若下一个存储区域未被完全读取,则计算机设备执行步骤811。若下一个存储区域被完全读取,则计算机设备执行步骤813。
在步骤813中,计算机设备将下一个存储区域的全局写指针作为当前全局写指针。
应理解,图8和图4存在类似的步骤。因此,关于图8的描述,可以参考图4中的描述。例如关于步骤801至步骤811的描述,可以参考前述图4中的步骤401至步骤411。关于步骤813的描述,可以参考步骤414的描述。并且,步骤812和步骤810之间并没有严格的时序限定。例如,计算机设备可以先执行步骤812。若下一个存储区域被完全读取,则计算机设备执行步骤810。
前面对本申请中的写入数据的方法进行描述。下面对本申请中读取数据的方法进行描述。具体地,图9为本申请中提供的读取数据的方法的第二个流程示意图。如图9所示,读取数据的方法包括以下步骤。
在步骤901中,计算机设备获取当前全局读指针,根据当前全局读指针确定当前存储区域。
在步骤902中,计算机设备确定当前写标识是否大于当前读标识。若当前写标识大于当前读标识,则计算机设备执行步骤904。若当前写标识小于或等于当前读标识,则计算机设备执行步骤903。
在步骤903中,结束。
在步骤904中,计算机设备确定当前全局写指针是否指向当前存储区域。若当前全局写指针指向当前存储区域,则计算机设备执行步骤905。若当前全局写指针当前存储区域以外的存储区域,则计算机设备执行步骤907。
在步骤905中,计算机设备确定当前区域内写偏移指针是否等于当前写标识。若当前区域内写偏移指针不等于当前写标识,则计算机设备执行步骤906。若当前区域内写偏移指针等于当前写标识,则计算机设备执行步骤908。
在步骤906中,结束。
在步骤907中,计算机设备确定当前存储区域是否被完全写入。若当前存储区域未被完全写入,则计算机设备执行步骤903。若当前存储区域被完全写入,则计算机设备执行步骤908。
在步骤908中,计算机设备确定当前全局读指针是否被修改。在前述步骤901中,计算机设备获取了当前全局读指针。在多线程并发的场景中,可能存在其它线程已经修改了 当前全局读指针。例如存在其它线程完成了后续的步骤910。因此,计算机设备再次获取当前全局读指针。若两次获取的当前全局读指针相同,则计算机设备确定当前全局读指针未被修改。若两次获取的当前全局读指针不同,则计算机设备确定当前全局读指针未被修改。若当前全局读指针未被修改,则计算机设备执行步骤909。若当前全局读指针被修改,则计算机设备执行步骤906。
在步骤909中,计算机设备确定当前子区域是否属于无效子区域。根据前面的描述可知,当前全局读指针指向当前子区域。若当前子区域不属于无效子区域,则计算机设备执行步骤910。若当前子区域属于无效子区域,则计算机设备执行步骤912。
在步骤910中,计算机设备读取当前子区域中的当前数据。计算机设备的当前线程执行抢头操作。若抢头成功,则计算机设备读取当前子区域中的当前数据。抢头成功则表征计算机设备更新了当前全局读指针。更新后的当前全局读指针指向当前子区域的下一个子区域的第一个字节。计算机设备将更新后的当前全局读指针作为当前全局读指针。若抢头失败,则计算机设备执行步骤906。
在步骤911中,计算机设备更新当前读标识。更新后的当前读标识等于当前数据的数据大小和当前读标识之和。例如,当前读标识等于250。当前数据的数据大小为40字节。则更新后的当前读标识等于290。
在步骤912中,计算机设备确定当前写区域指针是否大于当前读区域指针。若当前写区域指针大于当前读区域指针,则计算机设备执行步骤913。若当前写区域指针小于或等于当前读区域指针,则计算机设备执行步骤903。
在步骤913中,计算机设备更新当前全局读指针和当前全局读指针。更新后的当前全局读指针指向当前存储区域的下一个存储区域。具体地,更新后的当前全局读指针指向下一个存储区域的第一个子区域。计算机设备更新当前全局读指针。更新后的当前全局读指针等于当前全局读指针和目标无效子区域的空间大小之和。关于目标无效子区域的描述,可以参考前述图4中的相关描述。
应理解,图9和图7存在部分类似的步骤。因此,关于图9中的描述,可以参考前述图7中的描述。例如,关于步骤901的描述,可以参考前述图7中步骤701中的描述。关于步骤902至步骤907的描述,可以参考前述步骤704至步骤709中的描述。关于步骤907的描述可以参考前述步骤713的描述。关于步骤910和步骤911的描述,可以参考前述步骤714的描述。关于步骤912的描述,可以参考前述步骤715的描述。
前面对本申请中的数据处理方法进行描述,下面对本申请中的数据处理装置进行描述。图10为本申请中提供的数据处理装置的结构示意图。如图10所示,数据处理装置1000包括第一获取模块1001、第二获取模块1002、处理模块1003和读取模块1004。第一获取模块1001用于获取循环存储队列的第一全局读指针。循环存储队列包括M个存储区域。M为大于1的整数。第一全局读指针指向M个存储区域中的第一存储区域。第二获取模块1002用于获取第一存储区域的第一写标识。第一写标识表征第一存储区域中已存储数据的空间大小。处理模块1003用于确定第一存储区域中已被分配的空间大小。读取模块1004用于若满足第一条件,则读取第一子区域中的第一数据。第一条件包括:第一存储区域中已存储数据的空间大小等于第一存储区域中已被分配的空间大小。
在其他实施例中,数据处理装置1000还可以包括更新模块、清零模块等。程序运行装置中的模块具体用于执行图2、图4、图7、图8或图9对应的实施例中的计算机设备可以执行的全部或部分操作。
上面对本申请中的数据处理装置进行描述,下面对本申请实施例中的计算机设备进行描述。图11为本申请中提供的计算机设备的结构示意图。本申请中的计算机设备1100可以是台式电脑,笔记本,智能手机、交换机、基站等。如图11所示,计算机设备1100包括处理器1101和存储器1103。
其中,处理器1101可以是中央处理器(central processing unit,CPU),网络处理器(network processor,NP)或者CPU和NP的组合。处理器1101还可以进一步包括硬件芯片或其他通用处理器。上述硬件芯片可以是专用集成电路(application specific integrated circuit,ASIC),可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD),现场可编程逻辑门阵列(field-programmable gate array,FPGA),通用阵列逻辑(generic array logic,GAL)及其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等或其任意组合。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
存储器1103可以是易失性存储器或非易失性存储器,或可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(read-only memory,ROM)、可编程只读存储器(programmable ROM,PROM)、可擦除可编程只读存储器(erasable PROM,EPROM)、电可擦除可编程只读存储器(electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(random access memory,RAM),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(static RAM,SRAM)、动态随机存取存储器(dynamic RAM,DRAM)、同步动态随机存取存储器(synchronous DRAM,SDRAM)等。
存储器1103中存储有循环存储队列的第一全局读指针。循环存储队列包括M个存储区域。M为大于1的整数。第一全局读指针指向M个存储区域中的第一存储区域。存储器1103中还存储有第一存储区域的第一写标识。第一写标识表征第一存储区域中已存储数据的空间大小。处理器1101用于确定第一存储区域中已被分配的空间大小。处理器1101用于若满足第一条件,则读取第一子区域中的第一数据。第一条件包括:第一存储区域中已存储数据的空间大小等于第一存储区域中已被分配的空间大小。
在其他实施例中,计算机设备还包括收发器1102。收发器1102可以是光纤收发器,无线射频模块等。
在其他实施例中,存储器1103中存储有可供处理器1101执行的计算机程序。当处理器1101读取并执行计算机程序时,可以执行上述图2、图4、图7、图8或图9中数据处理方法中可以执行的全部或部分操作。
本申请还提供一种数字处理芯片。该数字处理芯片中集成了用于实现上述处理器1101的功能的电路和一个或者多个接口。当该数字处理芯片中集成了存储器时,该数字处理芯片可以完成前述实施例中的任意一个或多个实施例的方法步骤。当该数字处理芯片中未集成存储器时,可以通过接口与外置的存储器连接。该数字处理芯片根据外置的存储器中存 储的程序代码来实现上述图2、图4、图7、图8或图9中的数据处理方法。
以上,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。

Claims (23)

  1. 一种数据处理方法,其特征在于,包括:
    获取循环存储队列的第一全局读指针,所述循环存储队列包括M个存储区域,M为大于1的整数,所述第一全局读指针指向所述M个存储区域中的第一存储区域的第一子区域;
    获取所述第一存储区域的第一写标识,所述第一写标识表征所述第一存储区域中已存储数据的空间大小;
    若满足第一条件,则读取所述第一子区域中的第一数据;
    所述第一条件包括:所述第一存储区域中已存储数据的空间大小等于所述第一存储区域中已被分配的空间大小。
  2. 根据权利要求1所述的方法,其特征在于,所述方法还包括:
    根据所述循环存储队列的第一全局写指针确定所述第一存储区域中已被分配的空间大小;
    其中,若所述第一全局写指针指向所述第一存储区域以外的存储区域,则确定所述第一存储区域中已被分配的空间大小等于所述第一存储区域总的空间大小;
    和/或,若所述第一全局写指针指向所述第一存储区域,则确定所述第一存储区域中已被分配的空间大小等于第一字节的位置和所述第一存储区域的起始位置的差值,所述第一全局写指针指向所述第一存储区域中的所述第一字节。
  3. 根据权利要求1或2所述的方法,其特征在于,在读取所述第一子区域中的所述第一数据前,所述方法还包括:
    获取所述第一存储区域的第一读标识,所述第一读标识表征所述第一存储区域中已被读取的数据的数据大小;
    确定所述第一写标识和所述第一读标识的大小关系;
    所述第一条件还包括:所述第一写标识大于所述第一读标识。
  4. 根据权利要求1至3中任意一项所述的方法,其特征在于,所述第一子区域和所述第一数据的大小为X字节,X为大于0的整数;
    在读取所述第一子区域中的所述第一数据后,所述方法还包括:
    通过所述X更新所述第一存储区域的第一读标识,更新后的所述第一读标识等于所述第一读标识和所述X之和。
  5. 根据权利要求1至4中任意一项所述的方法,其特征在于,所述方法还包括:
    获取所述循环存储队列的第二全局写指针,所述第二全局写指针指向所述第一存储区域中的第二字节,所述第二字节为所述第一存储区域的起始位置;
    若所述第二字节的位置与所述第一存储区域的终点位置的差值大于或等于所述X,则在所述第一子区域中写入所述第一数据。
  6. 根据权利要求1至4中任意一项所述的方法,其特征在于,所述方法还包括:
    获取所述循环存储队列的第三全局写指针,所述第三全局写指针指向所述第一存储区域的第三字节;
    获取待写入的第二数据的大小,所述第二数据的大小为N字节;
    若所述第三字节的位置与所述第一存储区域的终点位置表征所述第一存储区域的剩余 区域小于所述N字节,则为所述剩余区域添加目标标识,所述目标标识用于表征所述剩余区域为无效子区域。
  7. 根据权利要求1至6中任意一项所述的方法,其特征在于,在读取所述第一子区域中的所述第一数据前,所述方法还包括:
    确定所述第一子区域中是否为无效子区域;
    所述第一条件还包括:所述第一子区域不是无效子区域。
  8. 根据权利要求6所述的方法,其特征在于,所述方法还包括:
    若满足第二条件,则更新所述第三全局写指针,更新后的所述第三全局写指针指向第二存储区域,所述第二存储区域为所述第一存储区域的下一个存储区域;
    所述第二条件包括:
    所述第二存储区域未被分配过,或第三全局读指针指向所述第二存储区域以外的存储区域,所述第二存储区域的第二写标识除以所述第二存储区域的总的空间大小等于整数,所述第二写标识表征所述第二存储区域中已存储数据的空间大小。
  9. 根据权利要求8所述的方法,其特征在于,在更新所述第三全局写指针前,所述方法还包括:
    将所述第二写标识清零;
    所述第一全局读指针包括第一读区域指针和第一区域内读偏移指针,所述第一读区域指针指向所述第一存储区域,所述第一区域内读偏移指针指向所述第一存储区域中的第二字节,所述第一全局写指针包括第一写区域指针和第一区域内写偏移指针;
    在读取所述第一子区域中的所述第一数据后,所述方法还包括:
    若所述第一读区域指针和所述第一写区域指针的差值大于所述M,则将所述第一读标识清零。
  10. 根据权利要求9所述的方法,其特征在于,所述方法还包括:
    若所述第一读区域指针和所述第一写区域指针的差值大于所述M,则更新所述第一读区域指针,更新后的所述第一读区域指针等于所述第一写区域指针和Z的差值,Z=M-1。
  11. 根据权利要求8所述的方法,其特征在于,
    所述第二条件还包括:所述第二存储区域的第二读标识除以所述第二存储区域的总的空间大小等于整数,所述第二读标识表征所述第二存储区域中已被读取的数据的数据大小。
  12. 一种数据处理装置,其特征在于,包括:
    第一获取模块,用于获取循环存储队列的第一全局读指针,所述循环存储队列包括M个存储区域,M为大于1的整数,所述第一全局读指针指向所述M个存储区域中的第一存储区域的第一子区域;
    第二获取模块,用于获取所述第一存储区域的第一写标识,所述第一写标识表征所述第一存储区域中已存储数据的空间大小;
    处理模块,用于确定所述第一存储区域中已被分配的空间大小;
    读取模块,用于若满足第一条件,则读取所述第一子区域中的第一数据;
    所述第一条件包括:所述第一存储区域中已存储数据的空间大小等于所述第一存储区域中已被分配的空间大小。
  13. 根据权利要求12所述的装置,其特征在于,
    所述处理模块用于确定所述第一存储区域中已被分配的空间大小包括:
    所述处理模块用于若所述第一全局写指针指向所述第一存储区域以外的存储区域,则确定所述第一存储区域中已被分配的空间大小等于所述第一存储区域总的空间大小;
    和/或,所述处理模块用于若所述第一全局写指针指向所述第一存储区域,则确定所述第一存储区域中已被分配的空间大小等于第一字节的位置和所述第一存储区域的起始位置的差值,所述第一全局写指针指向所述第一存储区域中的所述第一字节。
  14. 根据权利要求12或13所述的装置,其特征在于,
    所述第一获取模块还用于获取所述第一存储区域的第一读标识,所述第一读标识表征所述第一存储区域中已被读取的数据的数据大小;
    所述处理模块还用于确定所述第一写标识和所述第一读标识的大小关系;
    所述第一条件还包括:所述第一写标识大于所述第一读标识。
  15. 根据权利要求12至14中任意一项所述的装置,其特征在于,所述第一子区域和所述第一数据的大小为X字节,X为大于0的整数;
    所述装置还包括:
    更新模块,用于通过所述X更新所述第一存储区域的第一读标识,更新后的所述第一读标识等于所述第一读标识和所述X之和。
  16. 根据权利要求12至15中任意一项所述的装置,其特征在于,
    所述第一获取模块还用于获取所述循环存储队列的第二全局写指针,所述第二全局写指针指向所述第一存储区域中的第二字节,所述第二字节为所述第一存储区域的起始位置;
    所述装置还包括:
    写入模块,用于若所述第二字节的位置与所述第一存储区域的终点位置的差值大于或等于所述X,则在所述第一子区域中写入所述第一数据。
  17. 根据权利要求12至15中任意一项所述的装置,其特征在于,
    所述第一获取模块还用于获取所述循环存储队列的第三全局写指针,所述第三全局写指针指向所述第一存储区域的第三字节;
    所述第一获取模块还用于获取待写入的第二数据的大小,所述第二数据的大小为N字节;
    所述装置还包括:
    添加模块,用于若所述第三字节的位置与所述第一存储区域的终点位置表征所述第一存储区域的剩余区域小于所述N字节,则为所述剩余区域添加目标标识,所述目标标识用于表征所述剩余区域内为无效子区域。
  18. 根据权利要求12至17中任意一项所述的装置,其特征在于,
    所述处理模块还用于确定所述第一子区域是否为无效子区域;
    所述第一条件还包括:所述第一子区域不是无效子区域。
  19. 根据权利要求17所述的装置,其特征在于,所述装置还包括:
    更新模块,用于若满足第二条件,则更新所述第三全局写指针,更新后的所述第三全局写指针指向第二存储区域,所述第二存储区域为所述第一存储区域的下一个存储区域;
    所述第二条件包括:
    所述第二存储区域未被分配过,或第三全局读指针指向所述第二存储区域以外的存储区域,所述第二存储区域的第二写标识除以所述第二存储区域的总的空间大小等于整数,所述第二写标识表征所述第二存储区域中已存储数据的空间大小。
  20. 根据权利要求19所述的装置,其特征在于,所述装置还包括:
    清零模块,用于将所述第二写标识清零;
    所述第一全局读指针包括第一读区域指针和第一区域内读偏移指针,所述第一读区域指针指向所述第一存储区域,所述第一区域内读偏移指针指向所述第一存储区域中的第二字节,所述第一全局写指针包括第一写区域指针和第一区域内写偏移指针;
    所述清零模块还用于若所述第一读区域指针和所述第一写区域指针的差值大于所述M,则将所述第一存储区域中的第一读标识清零。
  21. 根据权利要求20所述的装置,其特征在于,
    所述更新模块还用于若所述第一读区域指针和所述第一写区域指针的差值大于所述M,则更新所述第一读区域指针,更新后的所述第一读区域指针等于所述第一写区域指针和Z的差值,Z=M-1。
  22. 根据权利要求19所述的装置,其特征在于,
    所述第二条件还包括:所述第二存储区域的第二读标识除以所述第二存储区域的总的空间大小等于整数,所述第二读标识表征所述第二存储区域中已被读取的数据的数据大小。
  23. 一种计算机设备,其特征在于,包括:存储器和处理器;
    所述存储器中存储有循环存储队列的第一全局读指针,所述循环存储队列包括M个存储区域,M为大于1的整数,所述第一全局读指针指向所述M个存储区域中的第一存储区域;
    所述存储器中还存储有所述第一存储区域的第一写标识,所述第一写标识表征所述第一存储区域中已存储数据的空间大小;
    所述处理器用于确定所述第一存储区域中已被分配的空间大小;
    所述处理器用于若满足第一条件,则读取第一子区域中的第一数据;
    所述第一条件包括:所述第一存储区域中已存储数据的空间大小等于所述第一存储区域中已被分配的空间大小。
PCT/CN2022/111739 2021-08-31 2022-08-11 数据处理方法、数据处理装置以及相关设备 WO2023029937A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP22863077.8A EP4386539A1 (en) 2021-08-31 2022-08-11 Data processing method, data processing apparatus, and related device
US18/589,722 US20240201907A1 (en) 2021-08-31 2024-02-28 Data processing method, data processing apparatus, and related device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111015761.0 2021-08-31
CN202111015761.0A CN115934023B (zh) 2021-08-31 2021-08-31 数据处理方法、数据处理装置以及相关设备

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US18/589,722 Continuation US20240201907A1 (en) 2021-08-31 2024-02-28 Data processing method, data processing apparatus, and related device

Publications (1)

Publication Number Publication Date
WO2023029937A1 true WO2023029937A1 (zh) 2023-03-09

Family

ID=85411930

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/111739 WO2023029937A1 (zh) 2021-08-31 2022-08-11 数据处理方法、数据处理装置以及相关设备

Country Status (4)

Country Link
US (1) US20240201907A1 (zh)
EP (1) EP4386539A1 (zh)
CN (1) CN115934023B (zh)
WO (1) WO2023029937A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024007745A1 (zh) * 2022-07-08 2024-01-11 华为技术有限公司 数据写入方法、读取方法、装置、电子设备以及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107247561A (zh) * 2017-05-31 2017-10-13 成都华立达电力信息***有限公司 缓冲池循环存储读写方法
US20180196603A1 (en) * 2013-05-17 2018-07-12 Huawei Technologies Co.,Ltd. Memory Management Method, Apparatus, and System
CN110474851A (zh) * 2019-08-01 2019-11-19 北京世纪东方通讯设备有限公司 一种循环存储结构的存取方法及装置
CN111694992A (zh) * 2019-03-15 2020-09-22 阿里巴巴集团控股有限公司 一种数据处理方法和装置
CN111930309A (zh) * 2020-07-31 2020-11-13 中国人民解放军海军工程大学 基于数据分块技术的文件循环存储方法和装置

Family Cites Families (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7500050B2 (en) * 2006-03-20 2009-03-03 International Business Machines Corporation Wise ordering for writes—combining spatial and temporal locality in write caches for multi-rank storage
US20080107396A1 (en) * 2006-11-08 2008-05-08 Tsung-Ning Chung Systems and methods for playing back data from a circular buffer by utilizing embedded timestamp information
TWI433163B (zh) * 2009-12-23 2014-04-01 Mstar Semiconductor Inc 記憶體控制器及其控制方法
CN101800867B (zh) * 2010-01-19 2011-09-28 深圳市同洲电子股份有限公司 一种实现环形缓冲区的方法、装置及数字电视接收终端
CN102591815B (zh) * 2011-12-27 2015-07-29 Tcl集团股份有限公司 一种用环形数据缓冲区读写批量数据的方法及装置
US9082204B2 (en) * 2012-08-30 2015-07-14 Qualcomm Incorporated Storage structures for stitching primitives in graphics processing
KR102029806B1 (ko) * 2012-11-27 2019-10-08 삼성전자주식회사 선입선출 버퍼를 포함하는 시스템 온 칩, 응용 프로세서 및 그것을 포함하는 모바일 장치
WO2017013931A1 (ja) * 2015-07-21 2017-01-26 ソニー株式会社 先入れ先出し制御回路、記憶装置、および、先入れ先出し制御回路の制御方法
US10713162B1 (en) * 2018-04-26 2020-07-14 Lightbits Labs Ltd. System and method for computer data garbage collection acceleration using peer to peer data transfers
CN108733344B (zh) * 2018-05-28 2023-07-04 深圳市道通智能航空技术股份有限公司 数据读写方法、装置以及环形队列
CN111865831B (zh) * 2019-04-30 2022-05-13 华为技术有限公司 数据处理的方法、网络设备、计算节点和***
CN110704335A (zh) * 2019-09-03 2020-01-17 苏州浪潮智能科技有限公司 一种基于异步环形缓冲区的数据读取、写入方法及装置
CN111506512B (zh) * 2020-04-24 2021-04-23 上海燧原智能科技有限公司 调试信息的处理方法、装置、电子设备、存储介质及***
CN111966498B (zh) * 2020-08-27 2023-08-25 南京电研电力自动化股份有限公司 一种配电房物联网网关数据快速处理方法、***及存储介质
CN112306413B (zh) * 2020-10-30 2024-05-07 北京百度网讯科技有限公司 用于访问内存的方法、装置、设备以及存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180196603A1 (en) * 2013-05-17 2018-07-12 Huawei Technologies Co.,Ltd. Memory Management Method, Apparatus, and System
CN107247561A (zh) * 2017-05-31 2017-10-13 成都华立达电力信息***有限公司 缓冲池循环存储读写方法
CN111694992A (zh) * 2019-03-15 2020-09-22 阿里巴巴集团控股有限公司 一种数据处理方法和装置
CN110474851A (zh) * 2019-08-01 2019-11-19 北京世纪东方通讯设备有限公司 一种循环存储结构的存取方法及装置
CN111930309A (zh) * 2020-07-31 2020-11-13 中国人民解放军海军工程大学 基于数据分块技术的文件循环存储方法和装置

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024007745A1 (zh) * 2022-07-08 2024-01-11 华为技术有限公司 数据写入方法、读取方法、装置、电子设备以及存储介质

Also Published As

Publication number Publication date
CN115934023B (zh) 2024-06-18
CN115934023A (zh) 2023-04-07
US20240201907A1 (en) 2024-06-20
EP4386539A1 (en) 2024-06-19

Similar Documents

Publication Publication Date Title
US11379324B2 (en) Persistent memory transactions with undo logging
US8095727B2 (en) Multi-reader, multi-writer lock-free ring buffer
US7542977B2 (en) Transactional memory with automatic object versioning
US8074030B1 (en) Using transactional memory with early release to implement non-blocking dynamic-sized data structure
US8677076B2 (en) System and method for tracking references to shared objects using byte-addressable per-thread reference counters
US10776120B2 (en) Apparatus and method to generate trace data in response to transactional execution
US11132294B2 (en) Real-time replicating garbage collection
US20080005504A1 (en) Global overflow method for virtualized transactional memory
US20130232495A1 (en) Scheduling accelerator tasks on accelerators using graphs
US11620215B2 (en) Multi-threaded pause-less replicating garbage collection
US20180300083A1 (en) Write-ahead logging through a plurality of logging buffers using nvm
US11714801B2 (en) State-based queue protocol
WO2023029937A1 (zh) 数据处理方法、数据处理装置以及相关设备
US11221947B2 (en) Concurrent garbage collection with minimal graph traversal
US9110791B2 (en) Optimistic object relocation
CN113626205B (zh) 处理器、物理寄存器管理方法及电子装置
CN111666339B (zh) 一种多线程数据同步方法
WO2024007745A1 (zh) 数据写入方法、读取方法、装置、电子设备以及存储介质
CN116627754A (zh) 一种命令超时监控方法、存储设备、电子设备及存储介质

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: 22863077

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2022863077

Country of ref document: EP

Effective date: 20240312

NENP Non-entry into the national phase

Ref country code: DE