CN109463002B - Method, device and equipment for storing data into queue - Google Patents

Method, device and equipment for storing data into queue Download PDF

Info

Publication number
CN109463002B
CN109463002B CN201580002944.5A CN201580002944A CN109463002B CN 109463002 B CN109463002 B CN 109463002B CN 201580002944 A CN201580002944 A CN 201580002944A CN 109463002 B CN109463002 B CN 109463002B
Authority
CN
China
Prior art keywords
queue
data
key name
tail
stored
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201580002944.5A
Other languages
Chinese (zh)
Other versions
CN109463002A (en
Inventor
罗庆超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Publication of CN109463002A publication Critical patent/CN109463002A/en
Application granted granted Critical
Publication of CN109463002B publication Critical patent/CN109463002B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a method, a device and equipment for storing data to a queue, and belongs to the field of data storage. The method comprises the following steps: receiving an enqueue request message, wherein the enqueue request message comprises data to be enqueued; determining the Key name of the data to be enqueued according to the queue identification of the queue and the enqueue sequence number of first data, wherein the first data is the data currently positioned at the tail of the queue; enqueue the Key name from the tail of the queue, and store a Key value KV pair comprising the Key name and the data to be enqueued in a KV storage system. The device comprises a receiving module, a determining module and a storage module. The queue stores the Key name determined by the queue identifier and the enqueue sequence number, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on KV pair storage data, the data do not need to be aligned and stored according to the minimum granularity, and the storage space is saved; and storing data to the KV storage system through the key value, and preventing the data from being lost when power is lost.

Description

Method, device and equipment for storing data into queue
Technical Field
The present invention relates to the field of data storage, and in particular, to a method, an apparatus, and a device for implementing a queue service.
Background
The queue is a special linear table and has the characteristic of FIFO (First In First Out ), namely, the queue only allows the insert operation to be performed at the back end (i.e. the tail) of the table, and the delete operation to be performed at the front end (i.e. the head) of the table, just because the queue has the characteristic, the queue has been widely used for storing data.
For example, currently, a device may store data generated by a program while the program is running, where the device includes a persistent storage medium, where the queue is located, and the storing process may be: when a program generates data, a processor of the device stores the data in the persistent storage medium, obtains a storage address of the data, and queues the storage address from the end of queue to enable the data to be stored in the queue.
In implementing the embodiments of the present invention, the inventors have found that the above-described technique has at least the following problems:
the minimum read-write granularity of the persistent storage medium is 4kb of space, and if the size of the data or the size of the storage address of the data is not an integer multiple of 4kb, the storage space is wasted.
Disclosure of Invention
In order to solve the problem that the storage space is wasted when the data are stored by adopting a persistent storage medium in the prior art, the invention provides a method, a device and equipment for storing the data to a queue. The technical scheme is as follows:
In a first aspect, a method for storing data to a queue is provided and applied to a storage device, where the storage device includes a processor and a memory, the processor is connected to the memory, the storage device further includes a key value KV storage system, and the processor is connected to the KV storage system, or the storage device is externally connected to the KV storage system, and the processor is connected to the KV storage system, and the processor executes the following procedures:
receiving an enqueue request message, wherein the enqueue request message comprises data to be enqueued;
determining the Key name of the data to be enqueued according to the queue identification of a queue and the enqueuing sequence number of first data, wherein the queue is positioned in the memory, and the first data is currently positioned at the tail of the queue;
enqueue the Key name from the tail of the queue, and store a Key value KV pair comprising the Key name and the data to be enqueued in the KV storage system.
In the first aspect, the Key names determined by the queue identification and the enqueue sequence number are stored in the queue, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on KV pair, data are stored in a KV storage system and Key names are stored in a memory, the KV storage system and the data in the memory do not need to be aligned and stored according to minimum granularity, and storage space is saved; the KV storage system is a persistent storage medium, and data is not lost when power is lost.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the determining, according to a queue identifier of a queue and an enqueue sequence number of first data, a Key name of the data to be enqueued includes:
adding the enqueuing sequence number of the first data to obtain the enqueuing sequence number of the data to be enqueued;
and forming a Key name of the data to be enqueued by the queue identifier of the queue and the enqueue sequence number.
In a first possible implementation manner of the first aspect: and adding the enqueuing sequence number of the first data, and combining the queue identification of the queue to obtain the Key name of the data to be enqueued, wherein after the enqueued data is enqueued, the Key names stored in each queue element are regularly circulated, so that the recovery of the queue is facilitated.
With reference to the first aspect or the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, the method further includes:
receiving a dequeue request message;
dequeuing the Key name stored at the head of the queue;
and acquiring data corresponding to the dequeued Key name from the KV storage system according to the dequeued Key name.
In a second possible implementation manner of the first aspect: according to the dequeued Key names, required data can be quickly obtained from the KV storage system, and the problem of storage space waste caused by the fact that the storage system must be sequentially stored is solved.
With reference to the first aspect, the first possible implementation manner of the first aspect, or the second possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect, the KV storage system includes a KV pair of a preset Key name and second data, where the second data includes a Key name stored at a head of a queue and a Key name stored at a tail of the queue, and the method further includes:
and when the head or tail of the queue changes, updating the head or tail of the queue stored in the KV storage system according to the preset Key name.
In a third possible implementation manner of the first aspect, second data composed of a Key name stored at the head of a queue and a Key name stored at the tail of the queue is stored in a KV storage system, so that power failure is not lost; and after the memory is powered down, acquiring the head or tail of the queue according to the preset Key name, and recovering the queue.
With reference to the first aspect or any one of the first to third possible implementation manners of the first aspect, in a fourth possible implementation manner of the first aspect, when a head or a tail of the queue changes, updating the head or the tail of the queue stored in the KV storage system according to the preset Key name includes:
When the head or tail of the queue changes, acquiring the Key name stored in the head and/or the Key name stored in the tail of the queue currently;
acquiring second data corresponding to the preset Key name from the KV storage system according to the preset Key name;
and updating the second data into the Key name stored in the head of the queue and the Key name stored in the tail of the queue currently.
In a fourth possible implementation manner of the first aspect, the head or the tail of the queue stored in the second data is updated in real time, so that it is ensured that the latest head and tail of the current queue are stored in the second data, and recovery of the queue and searching of the data are facilitated.
With reference to the first aspect or any one of the first to fourth possible implementation manners of the first aspect, in a fifth possible implementation manner of the first aspect, when the queue is lost, a head and a tail of the queue stored in the KV storage medium are obtained according to the preset Key name, and the queue is restored according to the head and the tail of the queue.
In a fifth possible implementation manner of the first aspect: when the abnormal power failure and other conditions occur to cause the queue data failure such as the loss of the queue data, the queue can be efficiently restored according to the preset offset value and the second data stored in the KV storage system.
With reference to the first aspect or any one of the first to fifth possible implementation manners of the first aspect, in a sixth possible implementation manner of the first aspect, the enqueuing sequence number of the Key name may be represented by a bit of a preset number of bits, and if the enqueuing sequence number of the first data is a maximum value represented by the bit of the preset number of bits, the enqueuing sequence number of the first data is increased, so that the enqueuing sequence number of the Key name corresponding to the data to be enqueued is 0.
In a sixth possible implementation manner of the first aspect: when the serial number of the data to be enqueued is greater than or equal to a preset threshold value, the data can be processed in a '0' returning mode, and the problem that the data cannot be continuously stored in the same queue due to the limitation of processing capacity is solved.
In a second aspect, there is provided an apparatus for storing data to a queue, comprising: the device comprises a receiving unit, a processing unit and a memory, wherein the processing unit is respectively connected with the receiving unit and the memory, the device also comprises a key value KV storage system, the processing unit is connected with the KV storage system, or the device is externally connected with the KV storage system, and the processing unit is connected with the KV storage system;
a receiving unit, configured to receive an enqueue request message, where the enqueue request message includes data to be enqueued;
The processing unit is used for determining the Key name of the data to be enqueued according to the queue identification of the queue and the enqueue sequence number of first data, wherein the first data is the data currently positioned at the tail of the queue; enqueue the Key name from the tail of the queue, and store a KV pair including the Key name and the data to be enqueued in a KV storage system.
In the second aspect, the Key names determined by the queue identification and the enqueue sequence number are stored in the queue, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on KV storage system storage data and memory storage Key names, the data do not need to be aligned and stored according to minimum granularity, and storage space is saved; and the KV storage system is used for storing data, and the data is not lost when power is lost.
With reference to the second aspect, in a first possible implementation manner of the second aspect,
the processing unit is used for increasing the enqueuing sequence number of the first data to obtain the enqueuing sequence number of the data to be enqueued; and forming a Key name of the data to be enqueued by the queue identifier of the queue and the enqueue sequence number.
In a first possible implementation manner of the second aspect: and adding the enqueuing sequence number of the first data, and combining the queue identification of the queue to obtain the Key name of the data to be enqueued, wherein after the enqueued data is enqueued, the Key names stored in each queue element are regularly circulated, so that the recovery of the queue is facilitated.
With reference to the second aspect or the first possible implementation manner of the second aspect, in a second possible implementation manner of the second aspect,
the receiving unit is further used for receiving a dequeue request message;
the processing unit is also used for dequeuing the Key name stored by the queue head of the queue; and acquiring data corresponding to the dequeued Key name from the KV storage system according to the dequeued Key name.
In a second possible implementation of the second aspect: according to the dequeued Key names, required data can be quickly obtained from the KV storage system, and the problem of storage space waste caused by the fact that the storage system must be sequentially stored is solved.
With reference to the second aspect, the first possible implementation manner of the second aspect, or the second possible implementation manner of the second aspect, in a third possible implementation manner of the second aspect, the KV storage system includes a KV pair of a preset Key name and second data, the second data includes a Key name stored at a head of a queue and a Key name stored at a tail of the queue,
and the processing unit is also used for updating the head or tail of the queue stored in the KV storage system according to the preset Key name when the head or tail of the queue changes.
In a third possible implementation manner of the second aspect: and second data consisting of the Key name stored in the head of the queue and the Key name stored in the tail of the queue are stored in the KV storage system, so that power failure cannot be lost.
With reference to the second aspect or any one of the first to third possible embodiments of the second aspect, in a fourth possible embodiment of the second aspect,
the processing unit is further used for acquiring the Key name stored in the head of the queue and/or the Key name stored in the tail of the queue currently when the head or the tail of the queue changes; acquiring second data corresponding to the preset Key name from the KV storage system according to the preset Key name; and updating the second data into the Key name stored in the head of the queue and the Key name stored in the tail of the queue currently.
In a fourth possible implementation manner of the second aspect: the head or tail of the queue stored in the second data is guaranteed to be stored with the latest head and tail of the current queue, and recovery of the queue and searching of the data are facilitated.
With reference to the second aspect or any one of the first to fourth possible embodiments of the second aspect, in a fifth possible embodiment of the second aspect,
And the processing unit is further used for acquiring the head and tail of the queue stored in the KV storage medium according to the preset Key name when the queue is lost, and recovering the queue according to the head and tail of the queue.
With reference to the second aspect or any one of the first to fifth possible implementation manners of the second aspect, in a sixth possible implementation manner of the second aspect, in the adding unit of the determining module, when a sequence number of the data to be enqueued is greater than or equal to a preset threshold, the sequence number generator redetermines the enqueued sequence number determined by the data to be enqueued to 0, that is, a "return to 0" process.
In a sixth possible implementation manner of the second aspect: when the serial number of the data to be enqueued is greater than or equal to a preset threshold value, the data can be processed in a '0' returning mode, and the problem that the data cannot be continuously stored in the same queue due to the limitation of processing capacity is solved.
In a third aspect, there is provided a storage device comprising: the storage device comprises a receiver, a processor and a memory, wherein the processor is respectively connected with the receiver and the memory, the storage device further comprises a key value KV storage system, the processor is connected with the KV storage system, or the storage device is externally connected with the KV storage system, and the processor is connected with the KV storage system;
The receiver is configured to receive an enqueue request message, where the enqueue request message includes data to be enqueued;
the processor is used for determining a Key Key name of the data to be enqueued according to a queue identifier of a queue and an enqueue sequence number of first data, wherein the queue is positioned in the memory, and the first data is currently positioned at the tail of the queue; enqueue the Key name from the tail of the queue, and store a KV pair including the Key name and the data to be enqueued in the KV storage system.
With reference to the third aspect, in a first possible implementation manner of the third aspect,
the processor is used for increasing the enqueuing sequence number of the first data to obtain the enqueuing sequence number of the data to be enqueued; and forming a Key name of the data to be enqueued by the queue identifier of the queue and the enqueue sequence number.
With reference to the third aspect or the first possible implementation manner of the third aspect, in a second possible implementation manner of the third aspect,
the receiver is further configured to receive a dequeue request message;
the processor is also used for dequeuing the Key name stored by the queue head of the queue; and acquiring data corresponding to the dequeued Key name from the KV storage system according to the dequeued Key name.
With reference to the third aspect, the first possible implementation manner of the third aspect, or the second possible implementation manner of the third aspect, in a third possible implementation manner of the third aspect,
the KV storage system comprises a KV pair of a preset Key name and second data, wherein the second data comprises a Key name stored at the head of a queue and a Key name stored at the tail of the queue;
and the processor is further used for updating the head or tail of the queue stored in the KV storage system according to the preset Key name when the head or tail of the queue changes.
With reference to the third aspect or any one of the first to third possible implementations of the third aspect, in a fourth possible implementation of the third aspect,
the processor is used for acquiring the Key name stored in the head of the queue and/or the Key name stored in the tail of the queue currently when the head or the tail of the queue changes; acquiring second data corresponding to the preset Key name from the KV storage system according to the preset Key name; and updating the second data into the Key name stored in the head of the queue and the Key name stored in the tail of the queue currently.
With reference to the third aspect or any one of the first to fourth possible embodiments of the third aspect, in a fifth possible embodiment of the third aspect,
and the processor is further used for acquiring the head and tail of the queue stored in the KV storage medium according to the preset Key name when the queue is lost, and recovering the queue according to the head and tail of the queue.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for storing data to a queue according to an embodiment of the present invention;
FIG. 2-1 is a flow chart of another method for storing data to a queue provided by an embodiment of the invention;
2-2 are schematic diagrams of an enqueue request provided by an embodiment of the present invention;
FIGS. 2-3 are schematic diagrams of data to be enqueued prior to enqueuing according to embodiments of the present invention;
FIGS. 2-4 are schematic diagrams of enqueuing data to be enqueued according to embodiments of the present invention;
FIGS. 2-5 are schematic diagrams of dequeue requests provided by embodiments of the present invention;
FIGS. 2-6 are schematic diagrams of dequeuing provided by embodiments of the present invention;
2-7 are diagrams of Key name lookup data according to dequeue provided by embodiments of the present invention;
FIGS. 2-8 are schematic diagrams of recovery lost queues provided by embodiments of the present invention;
FIG. 3 is a block diagram of an apparatus for storing data to a queue according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a connection relationship between a device for storing data in a queue and a KV storage system according to an embodiment of the present invention;
fig. 5 is a block diagram of a storage device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the embodiments of the present invention will be described in further detail with reference to the accompanying drawings.
Referring to fig. 1, a flowchart of a method for storing data in a queue is shown, where the method is applied to a storage device, the storage device includes a processor and a memory, the processor is connected with the memory, the storage device further includes a KV storage system, and the processor is connected with the KV storage system, or the storage device is externally connected with the KV storage system, and the processor is connected with the KV storage system, where the processor performs the following procedures, including:
Step 101: receiving an enqueue request message, wherein the enqueue request message comprises data to be enqueued;
step 102: determining the Key name of the data to be enqueued according to the queue identifier of the queue and the enqueuing sequence number of the first data, wherein the queue is positioned in the memory, and the first data is the data currently positioned at the tail of the queue;
step 103: enqueue the Key name from the tail of the queue, and store a Key Value (KV) pair comprising the Key name and the data to be enqueued in a KV storage system.
The technical scheme provided by the embodiment of the invention has the beneficial effects that: the Key names determined by the queue identification and the enqueue sequence number are stored in the queue, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on the memory storage Key name and the KV pair storage data, the data do not need to be aligned and stored according to the minimum granularity, and the storage space is saved; and storing data to the KV storage system through the key value, and preventing the data from being lost when power is lost.
The embodiment of the invention provides a method for storing data to a queue. The method is applied to the storage equipment, the storage equipment comprises a processor and a memory, the processor is connected with the memory, the storage equipment further comprises a KV storage system, the processor is connected with the KV storage system, or the storage equipment is externally connected with the KV storage system, and the processor is connected with the KV storage system. Under the condition that the storage device is externally connected with the KV storage system, the processor is connected with the KV storage system through a network card on the storage device.
The method execution body can be a processor, the processor forms a Key name with a queue identifier of a queue and the enqueuing sequence number by acquiring the enqueuing sequence number of data needing to be enqueued, the queue is positioned in a memory of a storage device, the Key name is enqueued from a queue tail of the queue, and a KV pair comprising the Key name and the data needing to be enqueued is stored in a KV storage system. Referring to fig. 2-1, the method includes:
step 201: an enqueue request message is received, the enqueue request message including data to be enqueued.
There is a queue in the memory of the storage device, which is used to provide a queue service for the running program, and the queue service is used for the processor of the storage device to store the data generated by the running program through the queue. When a program needs to store the generated data in the queue, the data is the data to be enqueued, and the program can submit an enqueue request message to the processor, wherein the enqueue request message carries the data to be enqueued. Accordingly, the processor begins executing this step.
For example, referring to fig. 2-2, assume that a running program, which submits an enqueue request message to a processor, generates data "and needs to store the data". The processor receives the enqueue request message, which carries the enqueue data to be found as "data".
Step 202: and determining the Key name of the data to be enqueued according to the queue identifier of the queue and the enqueue sequence number of the first data, wherein the first data is the Key name stored at the tail of the current queue.
Because the first data is the Key name stored at the tail of the current queue, the enqueuing sequence number of the first data is the enqueuing sequence number of the Key name enqueued from the tail of the queue last time, so in this step, the enqueuing sequence number of the first data can be increased to obtain the enqueuing sequence number of the Key name corresponding to the data to be enqueued, and the queue identifier of the queue and the enqueuing sequence number of the Key name corresponding to the data to be enqueued form the Key name of the data to be enqueued.
Optionally, adding a preset offset value to the enqueuing sequence number of the first data can obtain the enqueuing sequence number of the Key name corresponding to the to-be-enqueued data. The preset offset value may be a value of 1, 2 or 3.
Alternatively, the queue identifier of the queue may be the name of the queue, or the like.
Further, before executing this step, an enqueue sequence number of the first data is also acquired. The enqueuing sequence number of the first data can be stored when the enqueuing sequence number of the first data is obtained for the first time, and correspondingly, the stored enqueuing sequence number of the first data can be directly obtained before the step is executed.
Further, when the enqueuing sequence number of the Key name corresponding to the data to be enqueued is increased, the enqueuing sequence number of the stored first data can be updated to the enqueuing sequence number of the Key name corresponding to the data to be enqueued.
Alternatively, in this embodiment, a sequence number generator may be set in advance, and an enqueue sequence number of a Key name corresponding to data to be enqueued is generated by the sequence number generator. The method comprises the following steps:
the sequence number generator stores the enqueuing sequence number of the Key name which is enqueued from the tail of the queue last time, namely the enqueuing sequence number of the first data, and the sequence number generator adds the enqueuing sequence number stored by itself to obtain the enqueuing sequence number of the Key name corresponding to the data to be enqueued. Further, the sequence number generator also updates the queue entry sequence number stored by the sequence number generator to be the enqueue sequence number of the Key name corresponding to the data to be enqueued.
For example, it is assumed that the queue identifier is "MyQueue", the enqueue number of the first data is N, and the preset offset value is 1 in this embodiment, which is not a limitation of the protection scope of the present invention. As shown in fig. 2-3, a stored enqueuing sequence number N of the first data is obtained, the enqueuing sequence number N of the first data is increased by a preset offset value 1 to obtain an enqueuing sequence number n+1 of a Key name corresponding to the data to be enqueued, and then a queue identifier "MyQueue" of the queue and the enqueuing sequence number n+1 of the Key name corresponding to the data to be enqueued are formed to form the Key name corresponding to the data to be enqueued as "MyQueue n+1". Further, the enqueue sequence number N of the stored first data is updated to be the enqueue sequence number n+1 of the Key name corresponding to the data to be enqueued.
In this embodiment, the enqueuing sequence number of the Key name may be represented by a bit with a preset bit number, and if the enqueuing sequence number of the first data is the maximum value represented by the bit with the preset bit number, the enqueuing sequence number of the first data is increased, so as to obtain the enqueuing sequence number of the Key name corresponding to the data to be enqueued as 0.
The preset number of bits may be 4, 8, 16, 32 or 64, etc. For example, assuming that the preset bit number is 8 and the serial number of a Key name is 3, the first data may be represented as 00000011, assuming that the enqueuing serial number of the first data is the maximum value represented by 8 bits, that is, the enqueuing serial number of the first data is 11111111, adding the serial number of the first data to obtain the enqueuing serial number of the Key name corresponding to the data to be enqueued is 00000000, that is, the enqueuing serial number of the Key name corresponding to the data to be enqueued is 0.
It should be noted that the queue identifier may be a name or a number of the queue.
Step 203: and enqueuing the Key name of the data to be enqueued from the tail of the queue, and storing the KV pair comprising the Key name of the data to be enqueued and the data to be enqueued in a KV storage system.
In the step, the Key name of the data to be enqueued is used as the Key of the KV pair, the data to be enqueued is used as the Value of the KV pair, and then the Key name and the Value of the KV pair form a KV pair.
As shown in fig. 2-4, the Key name "MyQueue n+1" of the data to be enqueued "data" and the data to be enqueued "data" are combined into a KV pair "< MyQueue n+1, data >" and the KV pair is stored in the KV storage system.
The following description is needed: the KV storage system is a persistent storage system, so that data stored in the KV storage system cannot be lost after the KV storage system is powered down. In addition, the KV storage system does not need to store data according to the minimum storage granularity, and the storage space is occupied by how large actual data are in the KV storage system, so that the storage space waste does not exist.
Also to be described is: in this embodiment, each Key name is composed of a respective enqueue sequence number and a queue identifier of the queue, so when an abnormality occurs in a Key name, the Key name can be restored according to the Key names adjacent to the Key name.
For example, as shown in fig. 2-4, taking the preset offset value as 1 as an example, if the adjacent queue element before the element "MyQueue N" in the queue is lost, the sequence number "N-1" can be obtained by subtracting the preset offset value from the sequence number "N" of the queue element "MyQueue N", and then the queue element before the queue element "MyQueue N" can be obtained as "MyQueue N-1" according to the queue identifier "MyQueue"; if the adjacent queue element after the queue element 'MyQueue N' is lost, the element after the queue element 'MyQueue N' is 'MyQueue N+1' can be obtained by the same method.
Step 204: and updating the tail of the queue stored in the KV storage system according to the preset Key name.
The following description is needed: the KV storage system comprises: and presetting a KV pair consisting of a Key name and second data, wherein the second data comprises the Key name stored in the head of the queue and the Key name stored in the tail of the queue. When a data is stored into the queue for the first time, a Key name can be preset, the head and the tail of the queue are obtained, the obtained head and tail of the queue are used as second data, the preset Key name and the second data form a KV pair and are stored in a KV system, and then the second data are updated into the changed head and/or tail after the head and/or tail of the queue are changed.
Accordingly, the steps may be: and acquiring the Key name stored in the current tail of the queue, acquiring corresponding second data from the KV storage system according to the preset Key name, and updating the Key name stored in the tail of the second data into the currently acquired Key name. Or alternatively, the process may be performed,
obtaining the Key name stored in the current tail of the queue and the Key name stored in the head of the queue, obtaining corresponding second data from the KV storage system according to the preset Key name, and updating the second data into the Key name stored in the current tail of the queue and the Key name stored in the head of the queue.
For example, as shown in fig. 2-3, assuming that the preset Key name is "prekey", since the Key name stored by the current queue head is "MyQueue 1", the queue tail data is "MyQueue N", and thus the second data is "MyQueue 1& MyQueue N".
When the Key name of the data to be enqueued is enqueued, the Key name stored at the tail of the queue becomes "MyQueue N+1". Firstly, as shown in fig. 2-4, obtaining the updated tail-stored Key name "MyQueue n+1"; 2-3, obtaining second data 'MyQueue 1' and 'MyQueue N' from the KV storage system according to a preset Key name 'prekey'; as shown in fig. 2-4, the Key name "MyQueue N" stored in the queue tail in the second data is updated to the Key name "MyQueue n+1" stored in the currently acquired queue tail, that is, the updated second data is "MyQueue 1& MyQueue n+1". Or alternatively, the process may be performed,
2-4, obtaining a Key name 'MyQueue N+1' stored in the current tail of the queue and a Key name 'MyQueue 1' stored in the head of the queue; 2-3, according to a preset Key name 'preKey', corresponding second data 'MyQueue 1' and 'MyQueue N' are obtained from the KV storage system; as shown in fig. 2-4, the second data "MyQueue 1& MyQueue N" is updated to the currently acquired Key name "MyQueue n+1" stored in the tail of the queue and the Key name "MyQueue 1" stored in the head of the queue, i.e. the updated second data is "MyQueue 1& MyQueue n+1".
In addition to enqueuing requests, the running program may also request dequeue data from the queue, i.e., the program submits a enqueue request message and then dequeues the data by the following steps.
Step 205: and receiving a dequeue request message, dequeuing the Key name stored by the head of the queue.
For example, referring to fig. 2-5, assuming that the running program needs to take data, the program submits a team request message to the terminal. The terminal receives the dequeue request message, dequeues the Key name stored in the queue head, namely dequeues the Key name "MyQueue 1" stored in the queue head, as shown in fig. 2-6.
At this time, the queue head is dequeued, so that the queue head is updated to be a queue element behind the original queue head,
step 206: and acquiring data corresponding to the dequeued Key name from the KV pair stored in the KV storage system according to the dequeued Key name.
For example, as shown in fig. 2 to 7, according to the dequeued Key name "MyQueue 1", the data1 corresponding to the dequeued "MyQueue 1" is found in the KV storage system.
Step 207: and updating the queue head of the queue stored in the KV storage system according to the preset Key name.
The method comprises the following steps: and acquiring the Key name stored in the current queue head of the queue, acquiring corresponding second data from the KV storage system according to the preset Key name, and updating the Key name stored in the queue head in the second data into the currently acquired Key name. Or alternatively, the process may be performed,
Obtaining the Key name stored in the current tail of the queue and the Key name stored in the head of the queue, obtaining corresponding second data from the KV storage system according to the preset Key name, and updating the second data into the Key name stored in the current tail of the queue and the Key name stored in the head of the queue.
For example, still assume that the preset Key name is "preKey". After the Key name "MyQueue 1" stored in the queue head is dequeued, the Key name stored in the queue head becomes "MyQueue 2". First, as shown in fig. 2-7, the updated queue head stored Key name "MyQueue 2" is obtained; 2-6, obtaining second data 'MyQueue 1' and 'MyQueue N+1' from the KV storage system according to a preset Key name 'preKey'; as shown in fig. 2-7, the Key name "MyQueue 1" stored in the queue head in the second data is updated to the Key name "MyQueue 2" stored in the currently acquired queue head, that is, the updated second data is "MyQueue 2& MyQueue n+1". Or alternatively, the process may be performed,
2-7, obtaining a Key name 'MyQueue N+1' stored in the current queue head of the queue and a Key name 'MyQueue 2' stored in the queue head; 2-6, according to a preset Key name 'preKey', corresponding second data 'MyQueue 1' and 'MyQueue N+1' are obtained from the KV storage system; as shown in fig. 2-4, the second data "MyQueue 1& MyQueue n+1" is updated to the currently acquired Key name "MyQueue n+1" stored in the tail of the queue and the Key name "MyQueue 2" stored in the head of the queue, i.e. the updated second data is "MyQueue 2& MyQueue n+1".
Further, when the queue is lost due to memory power failure and the like, the head and the tail of the queue stored in the KV storage system can be obtained according to the preset Key name, and the queue is restored according to the head and the tail of the queue. The method comprises the following steps:
a queue is created in the memory, and the created queue is an empty queue. Obtaining second data stored in a KV storage system according to a preset Key name, obtaining a Key name i stored in a queue head of a lost queue and a Key name j stored in a queue tail, wherein i is an integer greater than or equal to 0, j is an integer greater than or equal to i, extracting an enqueue sequence number of the Key name i stored in the queue head and an enqueue sequence number of the Key name j stored in the queue tail from the Key name i stored in the queue head and the Key name j stored in the queue tail respectively, and extracting a queue identifier of the lost queue from the Key name i stored in the queue head or the Key name j stored in the queue tail.
Enqueuing the Key name i from the queue tail of the queue, acquiring a queue identifier of the queue and an enqueuing sequence number of the Key name i, which are included in the Key name i, increasing the enqueuing sequence number of the Key name i to obtain an enqueuing sequence number of the Key name i+1, forming the enqueuing sequence number of the Key name i+1 and the queue identifier of the queue into the Key name i+1, and enqueuing the Key name i+1 from the queue tail of the queue;
Adding an enqueue sequence number of the Key name i+1 to obtain an enqueue sequence number of the Key name i+2, forming the enqueue sequence number of the Key name i+2 and a queue identifier of the queue into the Key name i+2, and enqueuing the Key name i+2 from a queue tail of the queue; the method is carried out until the Key name j stored by the tail of the queue is enqueued from the tail of the queue.
For example, as shown in fig. 2-7, the lost queue may be restored according to the steps described above. Specifically, as shown in fig. 2-8, an empty queue is newly created, second data "MyQueue 2& MyQueue n+1" is obtained from the KV storage system according to a preset Key name "preKey", a queue identifier "MyQueue 2" of the lost queue, a Key name "MyQueue 2" stored in the head of the queue, a Key name "MyQueue n+1" stored in the tail of the queue are obtained from the second data, and accordingly, an enqueue sequence number of the Key name stored in the head of the queue is 2, and an enqueue sequence number of the Key name stored in the tail of the queue is n+1; enqueue the Key name "MyQueue 2" stored by the queue head from the tail of the newly built queue; adding an enqueue sequence number 2 of a Key name 'MyQueue 2', obtaining an enqueue sequence number '3', forming the increased enqueue sequence number 3 and a queue identifier 'MyQueue' into a Key name 'MyQueue 3', and enqueuing the combined Key name 'MyQueue 3' from the tail of the newly built queue; adding an enqueue sequence number 3 of a Key name 'MyQuue 3', obtaining an enqueue sequence number '4', forming the increased enqueue sequence number 4 and a queue identifier 'MyQuue' into a Key name 'MyQuue 4', enqueuing the combined Key name 'MyQuue 3' from the tail of the newly built queue, repeating the steps until the Key name 'MyQuue N+1' stored in the tail is combined, and enqueuing the Key name 'MyQuue N+1' from the tail of the newly built queue, thereby obtaining a queue identical to the lost queue, as shown in figures 2-8.
The technical scheme provided by the embodiment of the invention has the beneficial effects that: the Key names determined by the queue identification and the enqueue sequence number are stored in the queue, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on KV pair storage data, the data do not need to be aligned and stored according to the minimum granularity, and the storage space is saved; and storing data to the KV storage system through the key value, and preventing the data from being lost when power is lost.
And adding the enqueuing sequence number of the first data, and combining the queue identification of the queue to obtain the Key name of the data to be enqueued, wherein after the enqueued data is enqueued, the Key names stored in each queue element are regularly and circularly available, so that the recovery of the queue and the searching of the data are facilitated.
According to the dequeued Key names, required data can be quickly obtained from the KV storage system, and the problem of storage space waste caused by the fact that the storage system must be sequentially stored is solved.
And second data consisting of the Key name stored in the head of the queue and the Key name stored in the tail of the queue are stored in the KV storage system, so that power failure cannot be lost.
And updating the head or tail of the queue stored in the second data in real time, so as to ensure that the latest head and tail of the current queue are stored in the second data, and facilitate the recovery of the queue and the searching of the data.
When the queue is lost due to abnormal power failure and other conditions, the Key name stored at the head of the queue and the Key name stored at the tail of the queue can be obtained from the KV storage system according to the preset Key name, and the queue can be efficiently restored according to the Key name stored at the head of the queue and the Key name stored at the tail of the queue.
Referring to fig. 3, there is shown a block diagram of an apparatus 300 for storing data to a queue, the apparatus 300 comprising: the device 300 further comprises a KV storage system 340, see fig. 3, the processing unit 320 is connected with the receiving unit 310 and the memory 330 respectively, or the device 300 is externally connected with the KV storage system 340, see fig. 4, and the processing unit 320 is connected with the KV storage system 340;
a receiving unit 310, configured to receive an enqueue request message, where the enqueue request message includes data to be enqueued.
The processing unit 320 is configured to determine a Key name of the data to be enqueued according to a queue identifier of a queue and an enqueue sequence number of first data, where the queue is located in the memory 330, and the first data is data currently located at a tail of the queue; enqueue the Key name from the tail of the queue, and store a KV pair including the Key name and the data to be enqueued in KV storage system 340.
The technical scheme provided by the embodiment of the invention has the beneficial effects that: the Key names determined by the queue identification and the enqueue sequence number are stored in the queue, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on KV pair storage data, the data do not need to be aligned and stored according to the minimum granularity, and the storage space is saved; and storing data to the KV storage system through the key value, and preventing the data from being lost when power is lost.
Optionally, the processing unit 320 is configured to increase an enqueuing sequence number of the first data to obtain an enqueuing sequence number of the data to be enqueued; and forming the queue identifier and the enqueue sequence number of the queue into a Key name of the data to be enqueued.
Optionally, the receiving unit 310 is further configured to receive a dequeue request message;
the processing unit 320 is further configured to dequeue a Key name stored in a queue head of the queue; and acquiring data corresponding to the dequeued Key name from the KV storage system according to the dequeued Key name.
Optionally, the KV storage system comprises a KV pair of preset Key names and second data, the second data comprises the Key names stored at the head of the queue and the Key names stored at the tail of the queue,
the processing unit 320 is further configured to update the head or tail of the queue stored in the KV storage system according to the preset Key name when the head or tail of the queue changes.
Optionally, the processing unit 320 is configured to obtain, when a head or a tail of the queue changes, a Key name stored in the head and/or a Key name stored in the tail of the queue currently; acquiring second data corresponding to the preset Key name from the KV storage system according to the preset Key name; and updating the second data into the Key name stored in the head of the queue and the Key name stored in the tail of the queue.
Optionally, the processing unit 320 is further configured to obtain, when the queue is lost, a head and a tail of the queue stored in the KV storage medium according to the preset Key name, and restore the queue according to the head and the tail of the queue.
The technical scheme provided by the embodiment of the invention has the beneficial effects that: the Key names determined by the queue identification and the enqueue sequence number are stored in the queue, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on KV pair storage data, the data do not need to be aligned and stored according to the minimum granularity, and the storage space is saved; and storing data to the KV storage system through the key value, and preventing the data from being lost when power is lost.
And adding the enqueuing sequence number of the first data, and combining the queue identification of the queue to obtain the Key name of the data to be enqueued, wherein after the enqueued data is enqueued, the Key names stored in each queue element are regularly and circularly available, so that the recovery of the queue and the searching of the data are facilitated.
According to the dequeued Key names, required data can be quickly obtained from the KV storage system, and the problem of storage space waste caused by the fact that the storage system must be sequentially stored is solved.
And second data consisting of the Key name stored in the head of the queue and the Key name stored in the tail of the queue are stored in the KV storage system, so that power failure cannot be lost.
And updating the head or tail of the queue stored in the second data in real time, so as to ensure that the latest head and tail of the current queue are stored in the second data, and facilitate the recovery of the queue and the searching of the data.
It should be noted that: in the apparatus for storing data in a queue according to the foregoing embodiment, only the division of the foregoing functional modules is used for illustration, and in practical application, the foregoing functional allocation may be performed by different functional modules according to needs, that is, the internal structures of the terminal and the base station are divided into different functional modules, so as to perform all or part of the functions described above. In addition, the apparatus for storing data to a queue provided in the foregoing embodiments and the method embodiment for storing data to a queue are the same conception, and detailed implementation processes of the apparatus and the method embodiment are detailed in the foregoing method embodiment, and are not repeated herein.
Referring to fig. 5, an embodiment of the present invention provides a storage device 500 that may be used to perform the method described in fig. 2-1. Fig. 5 shows a structure of a storage device 500 provided by an embodiment of the present invention.
Fig. 5 is a block diagram showing a part of the structure of a storage device 500 according to an embodiment of the present invention. Referring to fig. 5, the storage device 500 includes a receiver 510, a processor 520, and a memory 530, the processor 520 is connected to the receiver 510 and the memory 530, respectively, the storage device 500 further includes a KV storage system 540 and the processor 520 is connected to the KV storage system 540, or the storage device 500 is externally connected to the KV storage system 540 and the processor 520 is connected to the KV storage system 540.
The storage device provided in this embodiment may further include, in addition to the above components, an input unit 550, a display unit 560, a sensor 570, a WiFi (wireless fidelity ) module 580, a power supply 590, and the like. It will be appreciated by those skilled in the art that the memory device 500 configuration shown in fig. 5 is merely an example of an implementation and is not limiting of the memory device 500, and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
The following describes the respective constituent elements of the storage device 500 in detail with reference to fig. 5:
Memory 530 may store one or more instructions that processor 520 may perform various functional applications and data processing of storage device 500 by executing the instructions stored in memory 530. The memory 530 may mainly include a storage program area and a storage data area, wherein the storage program area may store one or more instructions, an operating system, application programs (such as a sound playing function, an image playing function, etc.) required for at least one function, and the like.
The input unit 550 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the storage device 500. In particular, the input unit 550 may include a touch panel 551 and other input devices 552. The touch panel 551, also referred to as a touch screen, may collect touch operations thereon or thereabout by a user (e.g., operations of the user on the touch panel 551 or thereabout by using any suitable object or accessory such as a finger, a stylus, etc.), and drive the corresponding connection device according to a preset program. Alternatively, the touch panel 551 may include two parts of a touch detection device and a touch controller. The touch detection device detects the touch azimuth of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device and converts it into touch point coordinates, which are then sent to the processor 520, and can receive commands sent from the processor 520 and execute them. In addition, the touch panel 551 may be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. The input unit 550 may include other input devices 552 in addition to the touch panel 551. In particular, other input devices 552 may include, but are not limited to, one or more of a physical keyboard, function keys (e.g., volume control keys, switch keys, etc.), a trackball, mouse, joystick, etc.
The display unit 560 may be used to display information input by a user or information provided to the user and various menus of the storage device 500. The display unit 560 may include a display panel 561, and alternatively, the display panel 561 may be configured in the form of an LCD (Liquid Crystal Display ), an OLED (Organic Light-Emitting Diode), or the like. Further, the touch panel 551 may cover the display panel 561, and when the touch panel 551 detects a touch operation thereon or thereabout, the touch panel 551 is transferred to the processor 520 to determine the type of the touch event, and then the processor 520 provides a corresponding visual output on the display panel 561 according to the type of the touch event. Although in fig. 5, the touch panel 551 and the display panel 561 implement the input and input functions of the storage device 500 as two separate components, in some embodiments, the touch panel 551 and the display panel 561 may be integrated to implement the input and output functions of the storage device 500.
The storage device 500 may also include at least one sensor 570, such as a light sensor, a motion sensor, and other sensors. In particular, the light sensor may include an ambient light sensor that may adjust the brightness of the display panel 561 according to the brightness of ambient light, and a proximity sensor that may turn off the display panel 561 and/or the backlight when the storage device 500 moves to the ear. As one type of motion sensor, the accelerometer sensor can detect the acceleration in all directions (typically three axes), and can detect the gravity and direction when stationary, and can be used for recognizing storage device gestures (such as horizontal-vertical screen switching, related games, magnetometer gesture calibration), vibration recognition related functions (such as pedometer, knocking), and the like; other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc. that may also be configured with the storage device 500 are not described in detail herein.
WiFi belongs to a short-distance wireless transmission technology, and the storage device 500 can help a user to send and receive e-mails, browse web pages, access streaming media and the like through the WiFi module 580, so that wireless broadband Internet access is provided for the user. Although fig. 5 shows a WiFi module 580, it is understood that it does not belong to the necessary constitution of the storage device 500, and can be omitted entirely as required within a range that does not change the essence of the invention.
Processor 520 is a control center of storage device 500, and utilizes various interfaces and lines to connect various portions of the overall storage device, perform various functions of storage device 500 and process data by running or executing software programs and/or modules stored in memory 530, and invoking data stored in memory 530, thereby performing overall monitoring of the storage device. Optionally, the processor 520 may include one or more processing units; preferably, the processor 520 may integrate an application processor that primarily handles operating systems, user interfaces, applications, etc., with a modem processor that primarily handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 520.
The storage device 500 also includes a power supply 590 (e.g., a battery) for powering the various components, which may preferably be logically connected to the processor 520 by a power management system so as to perform functions such as managing charging, discharging, and power consumption by the power management system.
Although not shown, the storage device 500 may further include a camera, a bluetooth module, etc., which will not be described herein.
In an embodiment of the present invention, the storage device 500 includes the following functions of the receiver 510 and the processor 520:
a receiver 510 for receiving an enqueue request message, the enqueue request message comprising data to be enqueued;
a processor 520, configured to determine a key name of data to be enqueued according to a queue identifier of a queue and an enqueue sequence number of first data, where the first data is data currently located at a tail of the queue; enqueue the key name from the end of the queue, and store a KV pair including the key name and data to be enqueued in a KV storage system.
Optionally, the processor 520 is configured to increase the enqueuing sequence number of the first data to obtain the enqueuing sequence number of the data to be enqueued; and forming a key name of the data to be enqueued by the queue identifier of the queue and the enqueue sequence number.
Optionally, the receiver 510 is further configured to receive a dequeue request message;
processor 520, further configured to dequeue the key name stored at the head of the queue; and acquiring data corresponding to the dequeued key name from the KV storage system according to the dequeued key name.
Optionally, the KV storage system comprises a KV pair of preset key names and second data, the second data comprises key names stored at the head of the queue and key names stored at the tail of the queue,
the processor 520 is further configured to: and when the head or tail of the queue changes, updating the head or tail of the queue stored in the KV storage system according to the preset key name.
Optionally, the processor 520 is configured to obtain, when a head or a tail of the queue changes, a key name stored in the head and/or a key name stored in the tail of the queue currently; acquiring second data corresponding to the preset key name from the KV storage system according to the preset key name; and updating the second data into the key name stored in the head of the queue and the key name stored in the tail of the queue.
Optionally, the processor 520 is further configured to obtain a head and a tail of the queue stored in the KV storage system according to the preset key name when the queue is lost, and restore the queue according to the head and the tail of the queue.
The technical scheme provided by the embodiment of the invention has the beneficial effects that: the Key names determined by the queue identification and the enqueue sequence number are stored in the queue, so that the queue elements are orderly and orderly, and the recovery of the queue is facilitated; based on KV pair storage data, the data do not need to be aligned and stored according to the minimum granularity, and the storage space is saved; and storing data to the KV storage system through the key value, and preventing the data from being lost when power is lost.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, and are not repeated herein.
In the several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, and for example, the division of the units may be merely a logical function division, and there may be additional divisions when actually implemented, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is merely illustrative of the present invention, and the present invention is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (16)

1. A method for storing data to a queue, the method being applied to a storage device, the storage device including a processor and a memory, the processor being connected to the memory, the storage device further including a key value KV storage system and the processor being connected to the KV storage system, or the storage device being externally connected to the KV storage system and the processor being connected to the KV storage system, the processor performing the following steps:
receiving an enqueue request message, wherein the enqueue request message comprises data to be enqueued;
determining a Key Key name of the data to be enqueued according to a queue identifier of a queue and an enqueue sequence number of first data, wherein the queue is positioned in the memory, and the first data is currently positioned at the tail of the queue;
enqueuing the Key name from the tail of the queue, and storing a Key value KV pair comprising the Key name and the data to be enqueued in the KV storage system;
the determining the Key name of the data to be enqueued according to the queue identifier of the queue and the enqueue sequence number of the first data comprises the following steps:
adding a preset offset value to the enqueuing sequence number of the first data to obtain the enqueuing sequence number of the data to be enqueued;
And forming a Key name of the data to be enqueued by the queue identifier of the queue and the enqueue sequence number.
2. The method according to claim 1, wherein the method further comprises:
receiving a dequeue request message;
dequeuing the Key name stored at the head of the queue;
and acquiring data corresponding to the dequeued Key name from the KV storage system according to the dequeued Key name.
3. The method of claim 1 or 2, wherein the KV storage system includes a KV pair of a preset Key name and second data, the second data including a Key name stored at a head of the queue and a Key name stored at a tail of the queue, the method further comprising:
and when the head or tail of the queue changes, updating the head or tail of the queue stored in the KV storage system according to the preset Key name.
4. The method of claim 3, wherein updating the head or tail of the queue stored in the KV storage system according to the preset Key name when the head or tail of the queue changes, comprises:
when the head or tail of the queue changes, acquiring the Key name stored in the head and/or the Key name stored in the tail of the queue currently;
Acquiring second data corresponding to the preset Key name from the KV storage system according to the preset Key name;
and updating the second data into the Key name stored in the head of the queue and the Key name stored in the tail of the queue currently.
5. A method according to claim 3, characterized in that the method further comprises:
when the queue is lost, the head and the tail of the queue stored in the KV storage system are obtained according to the preset Key name, and the queue is restored according to the head and the tail of the queue.
6. An apparatus for storing data to a queue, the apparatus comprising: the device comprises a receiving unit, a processing unit and a memory, wherein the processing unit is respectively connected with the receiving unit and the memory, the device also comprises a key value KV storage system, the processing unit is connected with the KV storage system, or the device is externally connected with the KV storage system, and the processing unit is connected with the KV storage system;
the receiving unit is used for receiving an enqueue request message, wherein the enqueue request message comprises data to be enqueued;
the processing unit is used for determining a Key Key name of the data to be enqueued according to a queue identifier of a queue and an enqueue sequence number of first data, wherein the queue is positioned in the memory, and the first data is currently positioned at the tail of the queue; enqueuing the Key name from the tail of the queue, and storing a Key value KV pair comprising the Key name and the data to be enqueued in the KV storage system;
The determining the Key name of the data to be enqueued according to the queue identifier of the queue and the enqueue sequence number of the first data comprises the following steps:
adding a preset offset value to the enqueuing sequence number of the first data to obtain the enqueuing sequence number of the data to be enqueued;
and forming a Key name of the data to be enqueued by the queue identifier of the queue and the enqueue sequence number.
7. The apparatus of claim 6, wherein the device comprises a plurality of sensors,
the receiving unit is further used for receiving a dequeue request message;
the processing unit is also used for dequeuing the Key name stored by the queue head of the queue; and acquiring data corresponding to the dequeued Key name from the KV storage system according to the dequeued Key name.
8. The apparatus of claim 6 or 7, wherein the KV storage system comprises a KV pair of a preset Key name and second data, the second data comprising a Key name stored at the head of a queue and a Key name stored at the tail of the queue,
and the processing unit is also used for updating the head or tail of the queue stored in the KV storage system according to the preset Key name when the head or tail of the queue changes.
9. The apparatus of claim 8, wherein the device comprises a plurality of sensors,
The processing unit is used for acquiring the Key name stored in the head of the queue and/or the Key name stored in the tail of the queue currently when the head or the tail of the queue changes; acquiring second data corresponding to the preset Key name from the KV storage system according to the preset Key name; and updating the second data into the Key name stored in the head of the queue and the Key name stored in the tail of the queue currently.
10. The apparatus of claim 9, wherein the device comprises a plurality of sensors,
and the processing unit is further used for acquiring the head and tail of the queue stored in the KV storage system according to the preset Key name when the queue is lost, and recovering the queue according to the head and tail of the queue.
11. A storage device, the storage device comprising: the storage device comprises a receiver, a processor and a memory, wherein the processor is respectively connected with the receiver and the memory, the storage device further comprises a key value KV storage system, the processor is connected with the KV storage system, or the storage device is externally connected with the KV storage system, and the processor is connected with the KV storage system;
the receiver is configured to receive an enqueue request message, where the enqueue request message includes data to be enqueued;
The processor is used for determining a Key Key name of the data to be enqueued according to a queue identifier of a queue and an enqueue sequence number of first data, wherein the queue is positioned in the memory, and the first data is currently positioned at the tail of the queue; enqueuing the Key name from the tail of the queue, and storing a KV pair including the Key name and the data to be enqueued in the KV storage system;
the determining the Key name of the data to be enqueued according to the queue identifier of the queue and the enqueue sequence number of the first data comprises the following steps:
adding a preset offset value to the enqueuing sequence number of the first data to obtain the enqueuing sequence number of the data to be enqueued;
and forming a Key name of the data to be enqueued by the queue identifier of the queue and the enqueue sequence number.
12. The storage device of claim 11, wherein the memory is configured to store the data,
the receiver is further configured to receive a dequeue request message;
the processor is also used for dequeuing the Key name stored by the queue head of the queue; and acquiring data corresponding to the dequeued Key name from the KV storage system according to the dequeued Key name.
13. The storage device of claim 11 or 12, wherein the KV storage system comprises a KV pair of a preset Key name and second data, the second data comprising a Key name stored at a head of a queue and a Key name stored at a tail of the queue;
And the processor is further used for updating the head or tail of the queue stored in the KV storage system according to the preset Key name when the head or tail of the queue changes.
14. The storage device of claim 13, wherein the memory is configured to store the data,
the processor is used for acquiring the Key name stored in the head of the queue and/or the Key name stored in the tail of the queue currently when the head or the tail of the queue changes; acquiring second data corresponding to the preset Key name from the KV storage system according to the preset Key name; and updating the second data into the Key name stored in the head of the queue and the Key name stored in the tail of the queue currently.
15. The storage device of claim 14, wherein the memory is configured to store the data,
and the processor is further used for acquiring the head and tail of the queue stored in the KV storage system according to the preset Key name when the queue is lost, and recovering the queue according to the head and tail of the queue.
16. A computer storage medium having stored thereon a computer program which, when executed by a processor, implements the method according to any of claims 1-5.
CN201580002944.5A 2015-11-27 2015-11-27 Method, device and equipment for storing data into queue Active CN109463002B (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2015/095818 WO2017088180A1 (en) 2015-11-27 2015-11-27 Method, apparatus and device for storing data in queue

Publications (2)

Publication Number Publication Date
CN109463002A CN109463002A (en) 2019-03-12
CN109463002B true CN109463002B (en) 2023-09-22

Family

ID=58762922

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201580002944.5A Active CN109463002B (en) 2015-11-27 2015-11-27 Method, device and equipment for storing data into queue

Country Status (2)

Country Link
CN (1) CN109463002B (en)
WO (1) WO2017088180A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112291307A (en) * 2020-10-12 2021-01-29 北京思明启创科技有限公司 Data request processing method and device and electronic equipment
CN112784120B (en) * 2021-01-25 2023-02-21 浪潮云信息技术股份公司 KV memory database storage management method based on range fragmentation mode

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4042913A (en) * 1976-04-30 1977-08-16 International Business Machines Corporation Address key register load/store instruction system
US6032207A (en) * 1996-12-23 2000-02-29 Bull Hn Information Systems Inc. Search mechanism for a queue system
CN102663007A (en) * 2012-03-20 2012-09-12 广东电子工业研究院有限公司 Data storage and query method supporting agile development and lateral spreading
CN103810035A (en) * 2012-11-01 2014-05-21 国际商业机器公司 Intelligent context management
CN103902632A (en) * 2012-12-31 2014-07-02 华为技术有限公司 File system building method and device in key-value storage system, and electronic device

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7114156B2 (en) * 2002-03-29 2006-09-26 International Business Machines Corporation System and method for processing multiple work flow requests from multiple users in a queuing system
CN101222444B (en) * 2008-02-04 2011-11-09 华为技术有限公司 Caching data processing method, device and system
CN101751292B (en) * 2009-12-10 2012-11-07 四川川大智胜软件股份有限公司 Method for realizing consistency function of multimachine core data in ATC (automatic timing corrector) system
CN103647726B (en) * 2013-12-11 2017-01-11 华为技术有限公司 Message dispatching method and device thereof

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4042913A (en) * 1976-04-30 1977-08-16 International Business Machines Corporation Address key register load/store instruction system
US6032207A (en) * 1996-12-23 2000-02-29 Bull Hn Information Systems Inc. Search mechanism for a queue system
CN102663007A (en) * 2012-03-20 2012-09-12 广东电子工业研究院有限公司 Data storage and query method supporting agile development and lateral spreading
CN103810035A (en) * 2012-11-01 2014-05-21 国际商业机器公司 Intelligent context management
CN103902632A (en) * 2012-12-31 2014-07-02 华为技术有限公司 File system building method and device in key-value storage system, and electronic device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于流计算的实时监控预警架构研究及应用;朱征等;《华东电力》;20141124(第11期);全文 *

Also Published As

Publication number Publication date
CN109463002A (en) 2019-03-12
WO2017088180A1 (en) 2017-06-01

Similar Documents

Publication Publication Date Title
CN109768926B (en) Data processing method, terminal equipment and computer readable storage medium
EP3136214A1 (en) Touch operation method and apparatus for terminal
CN107943562B (en) Information storage method, information storage device, storage medium and electronic equipment
CN110391867B (en) DCI detection method, DCI sending method, terminal and base station
CN106649735B (en) Method and device for recording log data
CN108897486B (en) Display method and terminal equipment
CN111309205B (en) Application sharing method, first electronic device and computer-readable storage medium
US10922193B2 (en) Data backup method, storage medium, and terminal
CN109995862B (en) Resource scheduling method and terminal
CN109885573B (en) data storage system maintenance method, device and mobile terminal
CN108984066B (en) Application icon display method and mobile terminal
CN112262556B (en) Model file management method and terminal equipment
CN109463002B (en) Method, device and equipment for storing data into queue
CN115237618A (en) Request processing method and device, computer equipment and readable storage medium
CN111338745A (en) Deployment method and device of virtual machine and intelligent equipment
CN108933670A (en) A kind of digital signature method, device, mobile device and storage medium
CN109745699A (en) A kind of method and terminal device responding touch control operation
CN108270839B (en) Access frequency control system and method
CN109889568B (en) Data export method, server and system
CN116366521A (en) Flow table rule statistics method and device for data packet of network card
CN107688498B (en) Application program processing method and device, computer equipment and storage medium
CN115657943A (en) Data processing method, device and equipment for thin volume of storage system and storage medium
CN106357522B (en) Data sharing method and device
CN109902092B (en) Operation method and device of data storage system and mobile terminal
CN112367428A (en) Electric quantity display method and system, storage medium and mobile terminal

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant