Message order-preserving method and message order-preserving device
By combining a pre-set circular queue and a sorted queue, the problem of out-of-order packets at the receiving end caused by the selective retransmission mechanism is solved, thus achieving orderly data transmission and efficient resource utilization.
Patent Information
- Application Number
- CN202511632916.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-07
- Publication Date
- 2026-02-10
AI Technical Summary
Existing selective retransmission mechanisms are prone to causing out-of-order message delivery at the receiving end in data communication, and the retransmission mechanism also leads to resource waste.
A combination of a preset circular queue and a sorting queue is used. By determining whether the sequence number of a new message exceeds the sequence number range of the preset circular queue, the message is stored using the sorting queue, or the message is stored in the preset circular queue based on the sequence number difference, ensuring that messages are processed in order.
This enables the orderly processing of messages at the receiving end, avoiding resource waste caused by excessively large pre-set circular queue storage space, and ensuring the reliability and efficiency of data transmission.
Smart Images

Figure CN121509348A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data communication technology, and in particular to a message order preservation method and a message order preservation device. Background Technology
[0002] In the field of data communication, whether it is point-to-point communication or end-to-end communication, reliable data transmission has become a core requirement for the vast majority of network applications.
[0003] Reliable data transmission typically relies on retransmission mechanisms. If a message is lost at the receiving end, all subsequent messages must be discarded. After this process, the lost message and its subsequent messages are retransmitted to the receiving end to ensure that messages are processed in the correct order. However, this retransmission mechanism leads to duplicate message transmission, resulting in wasted resources. Therefore, a selective retransmission mechanism is proposed. This mechanism only retransmits the dropped messages, while subsequent messages are not retransmitted.
[0004] However, selective retransmission mechanisms are prone to causing out-of-order message problems at the receiving end. Summary of the Invention
[0005] Therefore, it is necessary to provide a message ordering method and device that can prevent out-of-order messages at the receiving end to address the above-mentioned technical problems.
[0006] Firstly, this application provides a message order preservation method, including:
[0007] If the sequence number of a new message sent by the receiving end exceeds the sequence number range of the preset circular queue, a sorted queue is used to store the message.
[0008] If the sequence number of the new message is within the sequence number range of the preset circular queue, then obtain the difference between the sequence number of the new message and the sequence number of the first initial position in the preset circular queue.
[0009] The newly arrived message is stored in a preset circular queue based on the difference.
[0010] In one embodiment, the method further includes:
[0011] After storing the new message in the preset circular queue, if the target position in the preset circular queue contains a message descriptor, then the descriptor of the first message at the target position is sent to the next node; the target position refers to the first initial position and at least one position sequentially connected to the first initial position.
[0012] Update the sequence number range of the preset circular queue to obtain the new sequence number range of the preset circular queue.
[0013] In one embodiment, the method further includes:
[0014] If the sequence number of the second message in the sorting queue is within the new sequence number range, the second message is treated as a new incoming message, and the process returns to obtain the difference between the sequence number of the new incoming message and the sequence number at the first initial position in the preset circular queue; the new incoming message is then stored in the preset circular queue based on the difference.
[0015] In one embodiment, the above-mentioned use of a sorted queue for message storage includes:
[0016] If there is a free storage location in the sorting queue, the descriptor of the new message is stored in the sorting queue according to the sequence number of the new message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue.
[0017] The second initial position refers to the smallest index position in the sorted queue where descriptors are stored; the ending position refers to the largest index position in the sorted queue where descriptors are stored.
[0018] In one embodiment, storing the descriptor of the new incoming message in the sorting queue based on the sequence number of the new incoming message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue includes:
[0019] If the sequence number of the new message is less than the sequence number of the second initial position, then the descriptor of the new message is stored in the position adjacent to the first starting position.
[0020] If the sequence number of the new message is greater than the sequence number of the end position, then the descriptor of the new message is stored in the position adjacent to the end position.
[0021] If the sequence number of the new message is between the sequence number of the first start position and the sequence number of the end position, then the descriptor of the new message is stored in the sorting queue according to the first difference between the sequence number of the new message and the sequence number of the second start position, and the second difference between the sequence number of the end position and the sequence number of the new message.
[0022] In one embodiment, storing the descriptor of the new message in the sorting queue based on the first difference between the sequence number of the new message and the sequence number of the second initial position, and the second difference between the sequence number of the end position and the sequence number of the new message, includes:
[0023] If the first difference is less than the second difference, and the first difference is not greater than the depth of the preset circular queue, then the descriptor of the newly arrived message is stored in the position adjacent to the second initial position.
[0024] If the first difference is less than the second difference and the first difference is greater than the depth value, then the descriptor of the new message is stored in the sorting queue based on the bubble sort method.
[0025] If the first difference is not less than the second difference, the descriptor of the new message is stored in the position adjacent to the end position.
[0026] In one embodiment, the method further includes:
[0027] If there is no free storage space in the sorting queue, and the sequence number of a new message is greater than the sequence number at the end of the sorting queue, the new message is discarded.
[0028] If the sequence number of a new message is less than the sequence number at the end of the sorting queue, the descriptor of the message at the end of the sorting queue is discarded.
[0029] In one embodiment, storing the newly arrived message into a preset circular queue based on the difference includes:
[0030] Based on the initial position, the difference, and the storage direction of the preset circular queue, the target position is determined, and the descriptor of the new message is stored in the target position.
[0031] Update the state at the target location to a non-empty state.
[0032] Secondly, this application also provides a message ordering device, comprising:
[0033] The receiving module is used to receive new incoming messages sent by the sending end. If the sequence number of the new incoming message exceeds the index range of the preset circular queue, a sorted queue is used to store the message.
[0034] The acquisition module is used to acquire the difference between the sequence number of the new message and the sequence number at the first initial position in the preset circular queue if the sequence number of the new message is within the index range of the preset circular queue.
[0035] The storage module is used to store new incoming messages into a preset circular queue based on the difference.
[0036] In one embodiment, the above-described apparatus further includes:
[0037] The sending module is used to store new incoming messages into a preset circular queue. If a message descriptor is stored at the target position in the preset circular queue, the descriptor of the first message at the target position is sent to the next node. The target position refers to the first initial position and at least one position sequentially connected to the first initial position.
[0038] The update module is used to update the sequence number range of the preset circular queue, thereby obtaining a new sequence number range for the preset circular queue.
[0039] In one embodiment, the above-described apparatus further includes:
[0040] The determination module is used to treat the second message as a new incoming message and return to the above-mentioned acquisition module and storage module if the message sequence number of the second message in the sorting queue is within the new sequence number range.
[0041] In one embodiment, the receiving module includes:
[0042] The first storage unit is specifically used to store the descriptor of the newly arrived message into the sorting queue according to the sequence number of the newly arrived message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue when there is a free storage location in the sorting queue; wherein, the second initial position refers to the smallest index position in the sorting queue where the descriptor is stored; and the end position refers to the largest index position in the sorting queue where the descriptor is stored.
[0043] In one embodiment, the first storage unit is further configured to: if the sequence number of the new message is less than the sequence number of the second initial position, store the descriptor of the new message at a position adjacent to the first starting position; if the sequence number of the new message is greater than the sequence number of the end position, store the descriptor of the new message at a position adjacent to the end position; if the sequence number of the new message is between the sequence number of the first starting position and the sequence number of the end position, store the descriptor of the new message in a sorting queue based on a first difference between the sequence number of the new message and the sequence number of the second initial position, and a second difference between the sequence number of the end position and the sequence number of the new message.
[0044] In one embodiment, the first storage unit is further configured to: if the first difference is less than the second difference and the first difference is not greater than the depth value of the preset circular queue, store the descriptor of the newly arrived message at a position adjacent to the second initial position; if the first difference is less than the second difference and the first difference is greater than the depth value, store the descriptor of the newly arrived message in the sorting queue based on the bubble sort method; and if the first difference is not less than the second difference, store the descriptor of the newly arrived message at a position adjacent to the end position.
[0045] In one embodiment, the receiving module includes:
[0046] The first discard unit is specifically used to discard a new message if the sequence number of the new message is greater than the sequence number of the end position in the sorting queue when there is no free storage space in the sorting queue.
[0047] The second discard unit is specifically used to discard the descriptor of the message at the end position if the sequence number of the newly arrived message is less than the sequence number at the end position in the sorting queue.
[0048] In one embodiment, the storage module includes:
[0049] The second storage unit is specifically used to determine the target location based on the first initial location, the difference, and the storage direction of the preset circular queue, and to store the descriptor of the newly arrived message at the target location.
[0050] The update unit is specifically used to update the state at the target location to a non-empty state.
[0051] The aforementioned message ordering method and device determine whether to use a sorted queue for message storage or to store the new message in the preset circular queue based on the difference between the new message's sequence number and the sequence number at the first initial position in the preset circular queue. This allows for message sorting based on the preset circular queue, ensuring that the message processing order at the receiving end matches the message sending order at the sending end, thus achieving ordered message reception. Furthermore, most end-to-end reliable transmissions currently use relatively large sequence numbers; if only... If only a preset circular queue is used for message storage, a relatively large preset circular queue is required to meet the requirements of sufficient data retransmission, which will consume a lot of buffer resources. In view of this, when the sequence number of a newly arrived message exceeds the sequence number range of the preset circular queue, this application uses a sorting queue to temporarily store the newly arrived message to avoid the storage space of the preset circular queue becoming too large. In addition, when the sequence number range of the preset circular queue covers the sequence number of the message in the sorting queue, the descriptor of the message in the sorting queue is stored in the corresponding position in the preset circular queue, thereby realizing the ordered reception of messages in the sorting queue. Attached Figure Description
[0052] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0053] Figure 1 This is a diagram of the first application environment of the message order preservation method in one embodiment.
[0054] Figure 2 This is a diagram illustrating the second application environment of the message order preservation method in one embodiment;
[0055] Figure 3 This is a flowchart illustrating a message order preservation method in one embodiment;
[0056] Figure 4 This is a schematic diagram of a pre-set circular queue in one embodiment;
[0057] Figure 5 This is a schematic diagram of a pre-set circular queue in another embodiment;
[0058] Figure 6 This is a flowchart illustrating the message order preservation method in another embodiment;
[0059] Figure 7 This is a schematic diagram of a pre-set circular queue in another embodiment;
[0060] Figure 8 This is a flowchart illustrating the message order preservation method in another embodiment;
[0061] Figure 9 This is a flowchart illustrating the message order preservation method in another embodiment;
[0062] Figure 10 This is a schematic diagram of a sorting queue in one embodiment;
[0063] Figure 11 This is a flowchart illustrating the message order preservation method in another embodiment;
[0064] Figure 12 This is a schematic diagram illustrating the storage of newly arriving packets in a sorting queue in one embodiment;
[0065] Figure 13 This is a schematic diagram illustrating the storage of newly arriving packets in a sorting queue in another embodiment;
[0066] Figure 14 This is a flowchart illustrating the message order preservation method in another embodiment;
[0067] Figure 15 This is a schematic diagram illustrating the storage of newly arriving packets in a sorting queue in another embodiment;
[0068] Figure 16 This is a schematic diagram illustrating the storage of newly arriving packets in a sorting queue in another embodiment;
[0069] Figure 17 This is a schematic diagram illustrating the storage of newly arriving packets in a sorting queue in another embodiment;
[0070] Figure 18 This is a flowchart illustrating the message order preservation method in another embodiment;
[0071] Figure 19 This is a flowchart illustrating the message order preservation method in another embodiment;
[0072] Figure 20 This is a flowchart illustrating the message order preservation method in another embodiment;
[0073] Figure 21 This is a structural block diagram of a message ordering device in one embodiment. Detailed Implementation
[0074] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0075] In the field of data communication, whether it is point-to-point communication or end-to-end communication, reliable data transmission has become a core requirement for the vast majority of network applications.
[0076] Reliable data transmission typically relies on retransmission mechanisms. If a message is lost at the receiving end, all subsequent messages must be discarded. After this process, the lost message and its subsequent messages are retransmitted to the receiving end to ensure that messages are processed in the correct order. However, this retransmission mechanism leads to duplicate message transmission, resulting in wasted resources. See also... Figure 1 The sending end first sends messages 0, 1, 2, 3, and 4 to the receiving end in sequence. After receiving message 0, the receiving end can process it and send an acknowledgment character (ACK) to the sending end after successful processing to inform the sending end that message 0 has been received without error. However, message 1 is lost during the transmission process from the sending end to the receiving end. The receiving end will send a negative acknowledgment character (NAK) to the sending end to inform the sending end that message 1 is erroneous and needs to be retransmitted. After receiving the NAK, in order to ensure that the receiving end processes the messages in the correct order, the sending end can retransmit messages 1, 2, 3, and 4 to the receiving end. However, messages 2, 3, and 4 sent the first time may have been received and processed normally by the receiving end. Therefore, retransmitting messages 2, 3, and 4 to the receiving end may lead to duplicate transmission of messages, resulting in wasted resources.
[0077] Based on this, a selective replay mechanism is proposed. This mechanism only retransmits dropped packets, while subsequent packets of the dropped packets are not retransmitted. See also Figure 2 The sending end first sends messages 0, 1, 2, 3, and 4 sequentially to the receiving end. After receiving message 0, the receiving end can process it and send an ACK to the sending end upon successful processing. However, message 1 is lost during transmission from the sending end to the receiving end, and the receiving end sends a NAK to the sending end. Upon receiving the NAK, the sending end can retransmit only message 1 to the receiving end, without retransmitting messages 2, 3, and 4. Assuming that messages 2, 3, and 4 can be received and processed normally by the receiving end, the order in which the receiving end receives and processes messages should be message 0, message 2, message 3, message 4, and message 1. Obviously, this selective retransmission mechanism is prone to causing out-of-order message problems at the receiving end. Based on this, this application provides a message order preservation method to solve the above problems.
[0078] Having described the background of the message order preservation method provided in this application, we can also introduce the implementation environment of the message order preservation method provided in this application. The message order preservation method provided in this embodiment can be applied to, for example, Figure 1 In the implementation environment shown, the implementation environment includes a sender 10 and a receiver 20. The sender 10 and the receiver 20 can be connected through a communication connection. The sender 10 can transmit messages to the receiver 20 through the communication connection, and the receiver 20 can also transmit messages to the sender 10 through the communication connection. It should be noted that each device in the data communication system can be either the sender 10 or the receiver 20.
[0079] In one embodiment, such as Figure 3 As shown, a message order preservation method is provided, which is applied to... Figure 1 Taking receiver 20 as an example, the following steps are included:
[0080] S201. Receive new incoming messages sent by the sending end. If the sequence number of the new incoming message exceeds the index range of the preset circular queue, then use a sorted queue to store the message.
[0081] A new incoming message refers to a message sent from the sender to the receiver. This message carries its sequence number, data, and protocol information. It should be noted that different new incoming messages have different sequence numbers.
[0082] A pre-defined circular queue refers to a circular storage space used to store message descriptors; it is a data structure type. A pre-defined circular queue can be a circular buffer. It can be pre-set in the receiving end. The message descriptor contains information such as the message's address and sequence number. A pre-defined circular queue can be used... Figure 4 This indicates that the preset circular queue includes multiple circular blocks, each corresponding to an index value. Consecutive circular blocks have consecutive index values. The index values corresponding to all circular blocks in the circular buffer constitute the index range of the preset circular queue. For example... Figure 4 The default index range for the circular queue is 0 to 7.
[0083] Each ring block can store a message descriptor. After the message descriptor is stored in the ring block, the sequence number corresponding to the position in the ring block can be updated to the sequence number of the message. For example, if the preset ring queue is empty and the preset ring queue receives message 0, the descriptor of message 0 can be stored in the first initial position of the preset ring queue, and the sequence number of the first initial position of the preset ring queue can be updated to 0. As another example, after storing the descriptor of message x in the corresponding position of the preset ring queue, the sequence number of that position can be updated to x.
[0084] After storing the message descriptor in the ring block, the state of the ring block storing the message descriptor can be modified to a non-empty state. The state of the ring block can be represented by a bitmap. If the ring block stores the message descriptor, the bitmap of the ring block can be updated to 1. If the ring block does not store the message descriptor, the bitmap of the ring block can be updated to 0.
[0085] When the preset circular queue does not yet store a message descriptor, the sequence number range of the preset circular queue is the same as the index range of the preset circular queue. That is, when the preset circular queue does not yet store a message descriptor, the sequence number range of the preset circular queue is 0 to 7.
[0086] It should be noted that a first initial position (base) can be set for the preset circular queue. This first initial position can be set to the position where the index value of the circular block is 0, or it can be set to the position where the index value of the circular block is any other value. Optionally, when no message descriptors are currently stored in the preset circular queue, the first initial position can be set to the position where the index value of the circular block is 0. After the message descriptor at the first initial position of the preset circular queue is delivered to the next node, the first initial position of the preset circular queue can be updated to the position where the descriptor is stored, or it can be updated to the position where no descriptor is stored. Furthermore, after the first initial position of the preset circular queue is updated, the sequence number range of the preset circular queue can be updated based on the sequence number of the message delivered to the next node. For example, please continue to see... Figure 4 If the descriptor of a message with a sequence number range of 0-3 in the preset circular queue is delivered to the next node, then the first initial position of the preset circular queue is updated to the position with an index range of 4, and the sequence number range of the preset circular queue is updated to 4-11. See [link to relevant documentation]. Figure 5 As shown.
[0087] Among them, the sorting queue refers to the storage queue that stores messages according to their sequence number, and it is also a type of data structure.
[0088] In this embodiment, after the receiving end receives a new incoming message sent by the sending end, it can parse the new incoming message to obtain the sequence number of the new incoming message, and determine whether the sequence number of the new incoming message exceeds the sequence number range of the preset circular queue. If the sequence number of the new incoming message exceeds the sequence number range of the preset circular queue, the message descriptor is stored in the sorting queue according to the message sequence number.
[0089] For example, please continue to see Figure 5 If the sequence number of the new message is 21, and the sequence number range of the preset circular queue is 4 to 11, then the sequence number of the new message exceeds the sequence number range of the preset circular queue. In this case, the descriptor of the new message can be stored in the sorting queue according to the sequence number of the new message.
[0090] S202. If the sequence number of the newly arrived message is within the index range of the preset circular queue, then obtain the difference between the sequence number of the newly arrived message and the sequence number at the first initial position in the preset circular queue.
[0091] In this embodiment, if it is determined that the sequence number of the newly arrived message is within the sequence number range of the preset circular queue, then the sequence number of the newly arrived message and the sequence number of the first initial position of the preset circular queue are obtained, and the difference between the sequence number of the newly arrived message and the sequence number of the first initial position of the preset circular queue is determined.
[0092] S203. Store the new message into a preset circular queue based on the difference.
[0093] In this embodiment, after determining the difference between the sequence number of the newly arrived message and the sequence number at the first initial position in the preset circular queue, the descriptor of the newly arrived message can be stored in the preset circular queue based on the difference between the sequence number of the newly arrived message and the sequence number at the first initial position in the preset circular queue.
[0094] For example, please continue to see Figure 5 If the descriptor of message 4 has already been stored at the first initial position base in the preset circular queue, and the sequence number of the new message is 8, then based on the difference of 4 between the sequence number of the new message and the sequence number at the first initial position in the preset circular queue, the new message can be stored at the position with sequence number 8 in the preset circular queue.
[0095] In this embodiment, by determining whether the sequence number of a newly arrived message exceeds the sequence number range of a preset circular queue, it is determined whether to use a sorted queue for message storage, or to store the newly arrived message in the preset circular queue based on the difference between the sequence number of the newly arrived message and the sequence number at the first initial position in the preset circular queue. This allows for message sorting based on the preset circular queue, ensuring that the message processing order at the receiving end is consistent with the message sending order at the sending end, thereby achieving ordered message reception. Furthermore, currently, most end-to-end reliable transmissions use relatively large sequence numbers; if only a preset queue is used… If a circular queue is used for message storage, a relatively large preset circular queue is required to meet the needs of sufficient data retransmission, which will consume a lot of buffer resources. In view of this, when the sequence number of a newly arriving message exceeds the sequence number range of the preset circular queue, this application uses a sorting queue to temporarily store the newly arriving message to avoid the storage space of the preset circular queue becoming too large. In addition, when the sequence number range of the preset circular queue covers the sequence number of the message in the sorting queue, the descriptor of the message in the sorting queue is stored in the corresponding position in the preset circular queue, thereby realizing the ordered reception of messages in the sorting queue.
[0096] In this embodiment, in the above Figure 3 Based on the illustrated embodiment, the detailed process of sending messages in a preset circular queue to the next node can be explained. In an exemplary embodiment, such as Figure 6 As shown, the above method also includes:
[0097] S204. After storing the new message in the preset circular queue, if the target position in the preset circular queue contains a message descriptor, then send the message descriptor at the target position to the next node; the target position refers to the first initial position and at least one position sequentially connected to the first initial position.
[0098] In this embodiment, after storing the new message into the preset circular queue, the state of the circular block storing the descriptor of the new message can be modified to a non-empty state. If the first initial position and at least one position sequentially connected to the first initial position in the preset circular queue store the descriptor of the message, then the first initial position and at least one position sequentially connected to the first initial position are sent to the next node.
[0099] For example, please continue to see Figure 5 If message descriptors are stored at both the first initial position (base) and the ring block sequence number 6, and the new message sequence number is 5, then the new message descriptor can be stored at the ring block sequence number 5. At this point, message descriptors are stored at the first initial position, the ring block sequence number 5, and the ring block sequence number 6. Therefore, the first initial position, the ring block sequence number 5, and the ring block sequence number 6 can be determined as the target positions, and then the message descriptor at the target position can be sent to the next node.
[0100] S205. Update the sequence number range of the preset circular queue to obtain a new sequence number range for the preset circular queue.
[0101] In this embodiment, after sending the descriptor of the first message at the target location to the next node, the sequence number range of the preset circular queue can be updated according to the sequence number of the first message at the target location to obtain a new sequence number range of the preset circular queue.
[0102] Continuing with the previous example, after submitting the descriptors of the messages at the first initial position, the sequence number 5 of the ring block, and the sequence number 6 of the ring block to the next node, the sequence number range of the preset ring queue can be updated as follows: Figure 7 The new sequence number range is shown. At the same time, the first initial position of the preset circular queue is updated, that is, the first initial position (base) of the preset circular queue is updated to the position of the circular block with sequence number 7.
[0103] In this embodiment, if the descriptor of the message is stored at the first initial position and at least one position sequentially connected to the first initial position in the preset circular queue, the message descriptor stored at the first initial position and at least one position sequentially connected to the first initial position can be sent to the next node to achieve sequential transmission of messages. In addition, after sending the message descriptor stored at the first initial position and at least one position sequentially connected to the first initial position to the next node, the sequence number range of the preset circular queue can be updated to ensure that the descriptors of messages in the sorting queue or the descriptors of other newly arrived messages can be stored in the preset circular queue, thereby achieving ordered reception of messages over a wider range.
[0104] In this embodiment, in the above Figure 6 Based on the illustrated embodiment, the detailed process of storing messages in the sorting queue to a preset circular queue will be explained. In an exemplary embodiment, such as Figure 8 As shown, the above method also includes:
[0105] S206. If the sequence number of the second message in the sorting queue is within the new sequence number range, treat the second message as a new incoming message and return to execute S202 and S203 above.
[0106] In this embodiment, after updating the sequence number range of the preset circular queue to obtain a new sequence number range for the preset circular queue, if there is at least one second message in the sorting queue and the sequence number of the second message is within the new sequence number range of the preset circular queue, then the second message is treated as a new incoming message, and the above steps S202-S203 are returned to be executed to store the descriptors of the messages in the sorting queue into the preset circular queue for message sorting processing.
[0107] For example, if the new sequence number range of the pre-defined circular queue is as follows: Figure 7 As shown, if there is a message with sequence number 11 in the sorting queue, the descriptor of the message with sequence number 11 can be stored in the corresponding position of the preset circular queue. The specific storage method includes: if the difference between the sequence number of the message with sequence number 11 and the sequence number of the message stored in the first initial position is 4, then the message with sequence number 11 is directly stored in the preset circular queue at the position with sequence number 11.
[0108] In this embodiment, a method is provided to store messages in a sorting queue into a preset circular queue, thereby ensuring the data source of the messages stored in the preset circular queue and avoiding the problem of resource waste caused by excessive storage space in the preset circular queue.
[0109] In this embodiment, in the above Figure 2Based on the illustrated embodiment, this embodiment will explain the detailed process of using a sorting queue for message storage. In an exemplary embodiment, such as Figure 9 As shown, the above S201 includes:
[0110] S301. If there is a free storage location in the sorting queue, store the descriptor of the new message in the sorting queue according to the sequence number of the new message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue.
[0111] Here, the second initial position refers to the smallest index position in the sorted queue where descriptors are stored; the ending position refers to the largest index position in the sorted queue where descriptors are stored. For example, in Figure 10 In the sorted queue shown, the position with sequence number 2 is the second initial position, and the position with sequence number 8 is the end position.
[0112] In this embodiment, it is first determined whether there is a free storage location in the sorting queue. If there is a free storage location in the sorting queue, the sequence number of the new incoming message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue are obtained. Then, according to the sequence number of the new incoming message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue, the descriptor of the message is stored in the sorting queue.
[0113] Optionally, a method is provided below for storing the descriptor of a newly arriving message into the sorting queue based on the sequence number of the newly arriving message, the sequence number at the second initial position in the sorting queue, and the sequence number at the end position in the sorting queue. See below. Figure 11 The aforementioned S301 includes:
[0114] S3010. If the sequence number of the new message is less than the sequence number of the second initial position, then the descriptor of the new message is stored in the position adjacent to the first starting position.
[0115] In this embodiment, after obtaining the sequence number of the new message, the sequence number of the second initial position, and the sequence number of the end position, if the sequence number of the new message is less than the sequence number of the second initial position, the descriptor of the new message is stored in the position adjacent to the first starting position.
[0116] Following the previous example, see [link / reference]. Figure 12 If the sequence number is 2, which is the second initial position, and the sequence number is 8, which is the end position, then if the sequence number of the new message is 0, the new message can be stored in the position adjacent to the second initial position.
[0117] S3011. If the sequence number of the new message is greater than the sequence number of the end position, then the descriptor of the new message is stored in the position adjacent to the end position.
[0118] In this embodiment, after obtaining the sequence number of the new message, the sequence number of the second initial position, and the sequence number of the end position, if the sequence number of the new message is greater than the sequence number of the end position, the descriptor of the new message is stored in a position adjacent to the end position.
[0119] Following the previous example, see [link / reference]. Figure 13 If the sequence number is 2, which is the second initial position, and the sequence number is 8, which is the end position, then if the sequence number of the new message is 10, the new message can be stored in the position adjacent to the end position.
[0120] S3012. If the sequence number of the new message is between the sequence number of the first starting position and the sequence number of the ending position, then the descriptor of the new message is stored in the sorting queue according to the first difference between the sequence number of the new message and the sequence number of the second starting position, and the second difference between the sequence number of the ending position and the sequence number of the new message.
[0121] In this embodiment, after obtaining the sequence number of the new message, the sequence number of the second initial position, and the sequence number of the end position, if the sequence number of the new message is between the sequence number of the first starting position and the sequence number of the end position, then the first difference between the sequence number of the new message and the sequence number of the second initial position is determined, and the second difference between the sequence number of the end position and the sequence number of the new message is determined. The descriptor of the new message is then stored in the sorting queue according to the first difference and the second difference.
[0122] Optionally, the following provides a specific implementation method for storing the descriptor of a newly arriving message into a sorting queue based on a first difference and a second difference. See [link to implementation details]. Figure 14 The aforementioned S3012 includes:
[0123] S30120. If the first difference is less than the second difference, and the first difference is not greater than the depth value of the preset circular queue, then the descriptor of the newly arrived message is stored in the position adjacent to the second initial position.
[0124] The depth value of the preset circular queue refers to the number of message descriptors that the preset circular queue can store. For example, Figure 4 The default depth of the circular queue is 8.
[0125] In this embodiment, if the first difference is less than the second difference, and the first difference is not greater than the depth of the preset circular queue, then the descriptor of the newly arrived message is stored in the position adjacent to the second initial position. For example, referring to 15, if the second initial position is at position 2 and the end position is at position 8, and the sequence number of the newly arrived message is 3, then the first difference between the sequence number of the newly arrived message and the sequence number of the second initial position is 1, while the second difference between the sequence number of the end position and the sequence number of the newly arrived message is 5. That is, the first difference is less than the second difference, so the descriptor of the newly arrived message is directly stored in the position adjacent to the second initial position.
[0126] S30121. If the first difference is less than the second difference and the first difference is greater than the depth value, then the descriptor of the newly arrived message is stored in the sorting queue based on the bubble sort method.
[0127] In this embodiment, if the first difference is less than the second difference and the first difference is greater than the depth of the preset circular queue, the descriptor of the newly arrived message is stored in the sorting queue based on bubble sort. For example, referring to 16, if the second initial position is at sequence number 2 and the end position is at sequence number 256, and the sequence number of the newly arrived message is 128, then the first difference between the sequence number of the newly arrived message and the sequence number at the second initial position is 126, while the second difference between the sequence number at the end position and the sequence number of the newly arrived message is 128. That is, the first difference is less than the second difference, so the descriptor of the newly arrived message is directly stored in the sorting queue based on bubble sort.
[0128] S30122. If the first difference is not less than the second difference, then the descriptor of the new message is stored in the position adjacent to the end position.
[0129] In this embodiment, if the first difference is not less than the second difference, the descriptor of the newly arrived message is stored in the position adjacent to the end position. For example, referring to 17, when the position with sequence number 2 is the second initial position and the position with sequence number 8 is the end position, if the sequence number of the newly arrived message is 6, then the first difference between the sequence number of the newly arrived message and the sequence number of the second initial position is 4, and the second difference between the sequence number of the end position and the sequence number of the newly arrived message is 2. That is, the first difference is not less than the second difference, so the descriptor of the newly arrived message is directly stored in the position adjacent to the end position.
[0130] The method provided in this embodiment for storing the descriptor of a newly arrived message in a sorting queue uses a sorting queue to temporarily store the newly arrived message in order to avoid the storage space of the preset circular queue being too large. It can also store the descriptor of the message in the sorting queue in the corresponding position in the preset circular queue when the sequence number range of the preset circular queue covers the sequence number of the message in the sorting queue, thereby realizing the order-preserving reception of the message in the sorting queue.
[0131] In this embodiment, in the above Figure 9 Based on the illustrated embodiment, the specific processing method for new packets when there is no free storage space in the sorting queue will be explained. In an exemplary embodiment, such as Figure 18 As shown, the above method also includes:
[0132] S302. If there is no free storage space in the sorting queue, and the sequence number of a new message is greater than the sequence number of the end position in the sorting queue, then the new message is discarded.
[0133] In this embodiment, if there is no free position in the sorting queue, and the sequence number of the new message is greater than the sequence number of the end position in the sorting queue, the new message is discarded, and after the new message is discarded, the receiving end sends NAK to the sending end.
[0134] S303. If the sequence number of the new message is less than the sequence number at the end of the sorting queue, then discard the message at the end of the sorting queue and store the descriptor of the new message in the sorting queue.
[0135] In this embodiment, if the sequence number of the new message is less than the sequence number at the end of the sorting queue, the descriptor of the message at the end of the sorting queue is discarded. After the descriptor of the message at the end of the sorting queue is discarded, the receiver sends NAK to the sender and then stores the descriptor of the new message at the end of the sorting queue.
[0136] In this embodiment, when the free storage space in the sorting queue is empty, a method is provided to first determine the larger sequence number between the sequence number of the newly arrived message and the sequence number at the end position in the sorting queue, and then discard the message corresponding to the larger sequence number. This greatly ensures that there is always a free storage space in the sorting queue, so that messages can be stored normally in the sorting queue.
[0137] In this embodiment, in the above Figure 3 Based on the illustrated embodiment, the specific processing method for storing newly arrived packets into a preset circular queue according to the difference will be explained. In an exemplary embodiment, such as Figure 19 As shown, the above S203 includes:
[0138] S401. Determine the target location based on the first initial location, the difference, and the storage direction of the preset circular queue, and store the descriptor of the newly arrived message at the target location.
[0139] In this embodiment, after determining the first initial position, the difference between the sequence number corresponding to the first initial position and the sequence number corresponding to the new message, and the storage direction of the preset circular queue, the target position can be determined based on the first initial position, the difference, and the storage direction of the preset circular queue, and the descriptor of the new message can be stored in the target position.
[0140] Please see Figure 4 If the sequence number corresponding to the first initial position in the preset circular queue is 0, and the sequence number corresponding to the new message is 6, then the difference between the sequence number corresponding to the first initial position and the sequence number corresponding to the new message is 6. Therefore, starting from the first initial position, following the storage direction of the preset circular queue, the position 5 positions away from the first initial position is determined as the target position. For example, if the sequence number corresponding to the first initial position in the preset circular queue is 0, and the sequence number corresponding to the new message is 4, then the difference between the sequence number corresponding to the first initial position and the sequence number corresponding to the new message is 4. Therefore, starting from the first initial position, following the storage direction of the preset circular queue, the position 3 positions away from the first initial position is determined as the target position.
[0141] S402. Update the state at the target location to a non-empty state.
[0142] In this embodiment, if a message is stored at the target location, the state at the target location is updated to a non-empty state.
[0143] This embodiment provides a specific implementation method for storing newly arrived messages in a preset circular queue, providing technical support for realizing the sequential transmission of messages.
[0144] In one embodiment, see Figure 20 It also provides a message order preservation method, including:
[0145] T1. Receive a new message sent by the sending end. If the sequence number of the new message exceeds the sequence number range of the preset circular queue, and if there is a free storage position in the sorting queue, if the sequence number of the new message is less than the sequence number of the second initial position, then store the descriptor of the new message in the position adjacent to the first starting position.
[0146] T2. If the sequence number of the new message is greater than the sequence number of the end position, then store the descriptor of the new message in the position adjacent to the end position.
[0147] T3. If the sequence number of the new message is between the sequence number of the first starting position and the sequence number of the ending position, then if the first difference is less than the second difference and the first difference is not greater than the depth value of the preset circular queue, then the descriptor of the new message is stored in the position adjacent to the second initial position.
[0148] T4. If the first difference is less than the second difference and the first difference is greater than the depth value, then the descriptor of the new message is stored in the sorting queue based on the bubble sort method.
[0149] T5. If the first difference is not less than the second difference, then store the descriptor of the new message in the position adjacent to the end position.
[0150] T6. If there is no free storage space in the sorting queue, and the sequence number of a new message is greater than the sequence number at the end of the sorting queue, then the new message is discarded.
[0151] T7. If the sequence number of a new message is less than the sequence number at the end of the sorting queue, then discard the descriptor of the message at the end of the sorting queue.
[0152] T8. If the sequence number of the new message is within the sequence number range of the preset circular queue, then obtain the difference between the sequence number of the new message and the sequence number of the first initial position in the preset circular queue.
[0153] T9. Determine the target location based on the first initial position, the difference, and the storage direction of the preset circular queue, and store the descriptor of the newly arrived message at the target location;
[0154] T10. Update the state at the target location to a non-empty state;
[0155] T11. If a message descriptor is stored at the target location in the preset circular queue, then the descriptor of the first message at the target location is sent to the next node; the target location refers to the first initial location and at least one location sequentially connected to the first initial location.
[0156] T12. Update the sequence number range of the preset circular queue to obtain the new sequence number range of the preset circular queue;
[0157] T13. If the sequence number of the second message in the sorting queue is within the new sequence number range, treat the second message as a new incoming message and return to execute T8-T9.
[0158] It should be noted that the descriptions of T1-T13 above can be found in the relevant descriptions in the above embodiments, and their effects are similar, so they will not be repeated here.
[0159] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0160] Based on the same inventive concept, this application also provides a message ordering device for implementing the message ordering method described above. The solution provided by this device is similar to the solution described in the above method; therefore, the specific limitations in one or more message ordering device embodiments provided below can be found in the limitations of the message ordering method described above, and will not be repeated here.
[0161] In one exemplary embodiment, such as Figure 21 As shown, a message order preservation device is provided, comprising: a receiving module 10, an acquisition module 11, and a storage module 12, wherein:
[0162] The receiving module 10 is used to receive new incoming messages sent by the sending end. If the sequence number of the new incoming message exceeds the sequence number range of the preset circular queue, a sorted queue is used to store the message.
[0163] The acquisition module 11 is used to acquire the difference between the sequence number of the newly arrived message and the sequence number of the first initial position in the preset circular queue if the sequence number of the newly arrived message is within the sequence number range of the preset circular queue.
[0164] Storage module 12 is used to store the new incoming message into the preset circular queue according to the difference.
[0165] In one exemplary embodiment, the above-described apparatus further includes:
[0166] The sending module is used to store the new incoming message into the preset circular queue, and if the target position in the preset circular queue contains a message descriptor, then send the descriptor of the first message at the target position to the next node; the target position refers to the first initial position and at least one position sequentially connected to the first initial position.
[0167] An update module is used to update the sequence number range of the preset circular queue to obtain a new sequence number range for the preset circular queue.
[0168] In one exemplary embodiment, the above-described apparatus further includes:
[0169] The determination module is used to determine the second message as a new incoming message when the message sequence number of the second message in the sorting queue is within the new sequence number range, and to execute the above-mentioned acquisition module 11 and storage module 12.
[0170] In an exemplary embodiment, the receiving module 10 includes:
[0171] The storage unit is specifically used to store the descriptor of the newly arrived message in the sorting queue according to the sequence number of the newly arrived message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue when there is a free storage location in the sorting queue; wherein, the second initial position refers to the smallest index position in the sorting queue where the descriptor is stored; and the end position refers to the largest index position in the sorting queue where the descriptor is stored.
[0172] In an exemplary embodiment, the storage unit is further configured to: if the sequence number of the newly arrived message is less than the sequence number of the second initial position, store the descriptor of the newly arrived message at a position adjacent to the first starting position; if the sequence number of the newly arrived message is greater than the sequence number of the ending position, store the descriptor of the newly arrived message at a position adjacent to the ending position; if the sequence number of the newly arrived message is between the sequence number of the first starting position and the sequence number of the ending position, store the descriptor of the newly arrived message in a sorting queue based on a first difference between the sequence number of the newly arrived message and the sequence number of the second initial position, and a second difference between the sequence number of the ending position and the sequence number of the newly arrived message.
[0173] In an exemplary embodiment, the storage unit is further configured to: if the first difference is less than the second difference and the first difference is not greater than the depth value of the preset circular queue, store the descriptor of the newly arrived message at a position adjacent to the second initial position; if the first difference is less than the second difference and the first difference is greater than the depth value, store the descriptor of the newly arrived message in the sorting queue based on bubble sort; if the first difference is not less than the second difference, store the descriptor of the newly arrived message at a position adjacent to the end position.
[0174] In an exemplary embodiment, the receiving module 10 further includes:
[0175] The first discarding unit is specifically used to discard the new message if the sequence number of the new message is greater than the sequence number of the end position in the sorting queue when there is no free storage space in the sorting queue.
[0176] The second discarding unit is specifically used to discard the descriptor of the message at the end position if the sequence number of the newly arrived message is less than the sequence number at the end position in the sorting queue.
[0177] In an exemplary embodiment, the storage module 12 includes:
[0178] The storage unit is specifically used to determine the target position based on the first initial position, the difference, and the storage direction of the preset circular queue, and to store the descriptor of the newly arrived message in the target position;
[0179] The update unit is specifically used to update the state at the target location to a non-empty state.
[0180] Each module in the aforementioned message order preservation device can be implemented entirely or partially through software, hardware, or a combination thereof.
[0181] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0182] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0183] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A message order preservation method, characterized in that, The method includes: If the sequence number of a newly received message exceeds the sequence number range of a preset circular queue, a sorted queue is used to store the message. If the sequence number of the newly arrived message is within the sequence number range of the preset circular queue, then the difference between the sequence number of the newly arrived message and the sequence number of the first initial position in the preset circular queue is obtained. The newly arrived message is stored in the preset circular queue based on the difference.
2. The method according to claim 1, characterized in that, The method further includes: After storing the new message in the preset circular queue, if the target position in the preset circular queue contains a message descriptor, then the descriptor of the first message at the target position is sent to the next node; the target position refers to the first initial position and at least one position sequentially connected to the first initial position. Update the sequence number range of the preset circular queue to obtain a new sequence number range for the preset circular queue.
3. The method according to claim 2, characterized in that, The method further includes: If the sequence number of the second message in the sorting queue is within the new sequence number range, the second message is treated as a new incoming message, and the process of obtaining the difference between the sequence number of the new incoming message and the sequence number at the first initial position in the preset circular queue is returned; the new incoming message is stored in the preset circular queue according to the difference.
4. The method according to claim 1, characterized in that, The method of using a sorted queue for message storage includes: If there is a free storage location in the sorting queue, the descriptor of the new message is stored in the sorting queue according to the sequence number of the new message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue. Wherein, the second initial position refers to the smallest index position in the sorting queue where descriptors are stored; the end position refers to the largest index position in the sorting queue where descriptors are stored.
5. The method according to claim 4, characterized in that, The step of storing the descriptor of the newly arrived message into the sorting queue based on the sequence number of the newly arrived message, the sequence number of the second initial position in the sorting queue, and the sequence number of the end position in the sorting queue includes: If the sequence number of the new message is less than the sequence number of the second initial position, then the descriptor of the new message is stored in the position adjacent to the first starting position; If the sequence number of the new message is greater than the sequence number of the end position, then the descriptor of the new message is stored in the position adjacent to the end position. If the sequence number of the newly arrived message is between the sequence number of the first starting position and the sequence number of the ending position, then the descriptor of the newly arrived message is stored in the sorting queue according to the first difference between the sequence number of the newly arrived message and the sequence number of the second starting position, and the second difference between the sequence number of the ending position and the sequence number of the newly arrived message.
6. The method according to claim 5, characterized in that, The step of storing the descriptor of the new incoming message in the sorting queue based on the first difference between the sequence number of the new incoming message and the sequence number of the second initial position, and the second difference between the sequence number of the end position and the sequence number of the new incoming message, includes: If the first difference is less than the second difference, and the first difference is not greater than the depth value of the preset circular queue, then the descriptor of the newly arrived message is stored in the position adjacent to the second initial position. If the first difference is less than the second difference and the first difference is greater than the depth value, then the descriptor of the newly arrived message is stored in the sorting queue based on the bubble sort method. If the first difference is not less than the second difference, then the descriptor of the newly arrived message is stored in a position adjacent to the end position.
7. The method according to claim 4, characterized in that, The method further includes: If there is no free storage space in the sorting queue, and the sequence number of the new message is greater than the sequence number of the end position in the sorting queue, then the new message is discarded. If the sequence number of the newly arrived message is less than the sequence number at the end position in the sorting queue, then the descriptor of the message at the end position is discarded.
8. The method according to claim 1, characterized in that, The step of storing the newly arrived message into the preset circular queue based on the difference includes: Based on the first initial position, the difference, and the storage direction of the preset circular queue, the target position is determined, and the descriptor of the newly arrived message is stored in the target position. Update the state at the target location to a non-empty state.
9. A message order preservation device, characterized in that, The device includes: The receiving module is used to receive new incoming messages sent by the sending end. If the sequence number of the new incoming message exceeds the index range of the preset circular queue, a sorted queue is used to store the message. The acquisition module is used to acquire the difference between the sequence number of the newly arrived message and the sequence number at the first initial position in the preset circular queue if the sequence number of the newly arrived message is within the index range of the preset circular queue. A storage module is used to store the newly arrived message into the preset circular queue according to the difference.
10. The apparatus according to claim 9, characterized in that, The device further includes: The sending module is used to store the new incoming message into the preset circular queue, and if the target position in the preset circular queue contains a message descriptor, then send the descriptor of the first message at the target position to the next node; the target position refers to the first initial position and at least one position sequentially connected to the first initial position. An update module is used to update the sequence number range of the preset circular queue to obtain a new sequence number range for the preset circular queue.