Data storage method, device, electronic device and storage medium

By combining data in the memory buffer and writing it to the hard disk at one time, the problem of low data storage performance in the persistent queue is solved, the head movement frequency of the mechanical hard disk is reduced, and the data writing efficiency is improved.

CN112099736BActive Publication Date: 2025-08-08TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011016833.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-24
Publication Date
2025-08-08
Estimated Expiration
2040-09-24

AI Technical Summary

Technical Problem

In the prior art, the data storage performance of the persistent queue is low, and the frequent mechanical movement of the magnetic head of the mechanical hard disk leads to the impact of the data writing performance.

Method used

The data to be stored is first stored in the memory buffer. When the write execution conditions are met, multiple data are combined into a second stored data and written to the hard disk. After successful, the data is stored in the memory queue.

Benefits of technology

Reduces the number of times to write to the hard disk, reduces the mechanical movement of the head of the mechanical hard disk, and improves data writing performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112099736B_ABST
    Figure CN112099736B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose a data storage method, device, electronic device and storage medium. Relate to the field of data storage. The method comprises: in response to a data storage request, storing the first storage data requested for storage in a memory buffer, wherein the first storage data is the data to be stored in the hard disk corresponding to the storage caller; when the write execution condition is met, writing the second storage data obtained by combining the multiple first storage data written in the memory buffer into the hard disk, wherein the hard disk is a mechanical hard disk; when the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored into the memory queue. This is conducive to reducing the number of times and the distance of the mechanical movement of the magnetic head triggered by the hard disk, improving the performance of writing data to the hard disk, and facilitating faster file storage in the hard disk.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data storage, and more specifically, to a data storage method, device, electronic device, and storage medium. Background Art

[0002] Electronic devices typically require a large amount of data storage, and various data storage methods are available. For example, in the persistent queue data storage process, data is first stored on the hard disk and then restored to memory. However, the performance of writing data to the hard disk during the persistent queue data storage process needs to be improved. Summary of the Invention

[0003] In view of the above problems, the present application proposes a data storage method, device, electronic device and storage medium to improve the above problems.

[0004] In a first aspect, the present application provides a data storage method, the method comprising: in response to a data storage request, storing the first storage data requested for storage in a memory buffer, the first storage data being the data to be stored in the hard disk corresponding to the storage caller; when a write execution condition is met, writing the second storage data obtained by combining multiple first storage data written into the memory buffer into the hard disk, wherein the hard disk is a mechanical hard disk; after the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored in a memory queue.

[0005] In the second aspect, the present application provides a data storage device, which includes: a data buffer unit for storing the first storage data requested for storage in a memory buffer in response to a data storage request, wherein the first storage data is the data to be stored in the hard disk corresponding to the storage caller; a persistent write unit for writing the second storage data obtained by combining multiple first storage data written in the memory buffer into the hard disk when the write execution condition is met, wherein the hard disk is a mechanical hard disk; a memory write unit for storing the first storage data written in the memory buffer into a memory queue after the second storage data is successfully written to the hard disk.

[0006] In a third aspect, the present application provides an electronic device comprising a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the above method.

[0007] In a fourth aspect, the present application provides a computer-readable storage medium, in which program code is stored, wherein the above method is executed when the program code is executed by a processor.

[0008] The present application provides a data storage method, device, electronic device and storage medium, which responds to a data storage request, stores the first storage data requested to be stored in the hard disk first in a memory buffer, and then when the write execution condition is met, writes the second storage data obtained by combining the multiple first storage data written to the memory buffer into the hard disk, and then when the second storage data is successfully written to the hard disk, stores the first storage data written to the memory buffer into the memory queue. Thus, by combining the multiple first storage data written to the memory buffer, it is possible to combine the multiple first storage data to obtain a second storage data, and then realize the operation of writing data to the hard disk once, and the multiple first storage data combined to obtain the second storage data can be written to the hard disk, reducing the number of times the hard disk is written. In addition, the mechanical hard disk locates the data write position based on the mechanical movement of the magnetic head during the data writing process. Then, when the number of times the hard disk is written is reduced, it is beneficial to reduce the number and movement distance of the mechanical movement of the magnetic head triggered by the hard disk, thereby improving the performance of writing data to the hard disk. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0010] Figure 1 A schematic diagram of a persistent queue is shown;

[0011] Figure 2 A schematic diagram showing an application environment of a data storage method in an embodiment of the present application is shown;

[0012] Figure 3 A schematic diagram showing an application environment of another data storage method according to an embodiment of the present application is shown;

[0013] Figure 4 A flowchart of a data storage method proposed in one embodiment of the present application is shown;

[0014] Figure 5 A flowchart of a data storage method proposed in another embodiment of the present application is shown;

[0015] Figure 6 A schematic diagram illustrating determining a write execution condition based on a deadline in an embodiment of the present application is shown;

[0016] Figure 7A schematic diagram showing the conditions included in the write execution condition determined in multiple stages in an embodiment of the present application is shown;

[0017] Figure 8 A schematic diagram showing second stored data obtained by a combination in an embodiment of the present application is shown;

[0018] Figure 9 A schematic diagram showing changes to a storage instruction after combining first storage data in an embodiment of the present application is shown;

[0019] Figure 10 A schematic diagram showing how first stored data are spliced to obtain second stored data in an embodiment of the present application is shown;

[0020] Figure 11 A schematic diagram showing the process of retrieving first stored data from a memory queue in an embodiment of the present application is shown;

[0021] Figure 12 A flowchart of a data storage method proposed in another embodiment of the present application is shown;

[0022] Figure 13 A flowchart of a data storage method proposed in another embodiment of the present application is shown;

[0023] Figure 14 A flowchart of a data storage method proposed in another embodiment of the present application is shown;

[0024] Figure 15 A structural block diagram of a data storage device proposed in an embodiment of the present application is shown;

[0025] Figure 16 A structural block diagram of a data storage device proposed in another embodiment of the present application is shown;

[0026] Figure 17 A structural block diagram of another electronic device for executing the data storage method according to an embodiment of the present application is shown;

[0027] Figure 18 A storage unit for storing or carrying program codes for implementing the data storage method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0028] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0029] As computer systems become increasingly versatile, they generate a significant amount of data that needs to be stored. For example, if a data processing task assigned by a computer system is not immediately processed, the received data processing task will be stored. As a storage method, electronic devices can use persistent queues to store the required data.

[0030] Among them, persistent queue is a reliable storage method, such as Figure 1 As shown, the persistent queue includes a memory queue, which is a queue running in memory, and the data in the memory queue is also stored in the form of a file on the hard disk. Therefore, the persistent queue can be understood as consisting of a memory queue and a file stored on the hard disk. This allows the data to be restored from the hard disk to the memory queue even when the data in the memory is cleared for some reason, thereby achieving reliable data storage for the persistent queue. When storing data through a persistent queue, a copy of the data to be stored is first stored on the hard disk, and then the same data is stored in the queue.

[0031] However, the inventors found in their research that the data storage performance of the relevant persistent queues needs to be improved. Specifically, the inventors found in their research on the data storage method of the relevant persistent queues that in the relevant method, whenever there is data that needs to be stored, a data storage operation will be performed immediately, and each time a data storage operation is performed, an operation of writing data to the hard disk will be performed. However, for mechanical hard disks, the data reading and writing positions are located by mechanical movement of the magnetic head, and each data writing operation is performed based on random writing, which will require the hard disk to locate the data writing position by mechanical movement of the magnetic head each time an operation of writing data to the hard disk is performed. Excessive mechanical movement of the magnetic head will affect the data writing performance.

[0032] Therefore, in order to improve the above problems, the embodiments of the present application provide a data storage method, device, electronic device and storage medium, which responds to a data storage request, first stores the first storage data requested to be stored in the hard disk in a memory buffer, and then when the write execution condition is met, writes the second storage data obtained by combining multiple first storage data written in the memory buffer into the hard disk, and then when the second storage data is successfully written to the hard disk, stores the first storage data written in the memory buffer into a memory queue.

[0033] Thus, by combining the multiple first storage data written to the memory buffer, the multiple first storage data can be combined to obtain a second storage data, and then the multiple first storage data combined to obtain the second storage data can be written to the hard disk by performing a data write operation once, thereby reducing the number of write operations to the hard disk. In addition, the mechanical hard disk locates the data write position based on the mechanical movement of the magnetic head during the data writing process. Therefore, when the number of write operations to the hard disk is reduced, it is beneficial to reduce the number of times and the movement distance of the mechanical movement of the magnetic head triggered by the hard disk, thereby improving the performance of writing data to the hard disk.

[0034] Before further describing the embodiments of the present application in detail, the application environment involved in the embodiments of the present application is introduced.

[0035] like Figure 2 As shown, Figure 2 The figure shows a schematic diagram of an application environment involved in an embodiment of the present application. It includes a client 10 and a server 20. The client 10 can generate a data storage request and then send the generated processing request to the server 20. The data storage method provided by the embodiment of the present application can be run in the server 20. After the server 20 receives the data storage request, it can further perform subsequent processing based on the data storage method provided by the embodiment of the present application. The client 10 can be understood as a storage caller, so Figure 1 The environment shown may also include other clients besides the client 10, and each client may be regarded as a storage caller.

[0036] It should be noted that the server 20 may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The electronic device where the client 10 is located may be a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited thereto.

[0037] like Figure 3 As shown, Figure 3 FIG. 1 is a schematic diagram of another application environment involved in the embodiment of the present application. Figure 3In the embodiment, the client 40 and the system component 50 both run in the same electronic device 30. In this way, the client 40 can generate a data storage request and then send the generated processing request to the system component 50. The data storage method provided in the embodiment of the present application can run in the system component 50 therein. After the system component 50 receives the data storage request, it can further perform subsequent processing based on the data storage method provided in the embodiment of the present application.

[0038] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0039] See also Figure 4 , Figure 4 FIG2 is a flow chart of a data storage method proposed in an embodiment of the present application, the method comprising:

[0040] S110: In response to a data storage request, first storage data requested for storage is stored in a memory buffer, where the first storage data is data to be stored in a hard disk corresponding to the storage caller.

[0041] As a method, a storage caller that needs to store data can trigger the data storage process by sending a data storage request. The first storage data requested for storage is the first storage data requested by the data storage request. After receiving the data storage request, the server or system component executing the data storage method provided in this embodiment can use the requested data as the first storage data and store the first storage data in a memory buffer. The memory buffer can be a data buffer area in the memory that is different from the memory queue.

[0042] It should be noted that, in this embodiment, the first stored data is not written into the memory buffer as a trigger to write the received first stored data into the hard disk, but it is necessary to wait until the subsequent writing conditions are met before executing the operation of writing the first stored data in the memory buffer to the hard disk. The received first stored data can be stored in the memory buffer for temporary storage.

[0043] The server or system component that executes the data storage method may have multiple ways of obtaining the first storage data.

[0044] As a method, the first storage data may be carried in the data storage request. In this method, the first storage data may be obtained from the data storage request by parsing the data storage request.

[0045] Alternatively, after receiving the data storage request, the server or system component may send a response message to the application that sent the data storage request. After receiving the response message, the application may return the first stored data in response to the response message.

[0046] Optionally, the data content of the first stored data may be determined based on the application scenario of the data storage method proposed in this embodiment. For example, if the application scenario is a log system, the content of the first stored data may be logs. If the application scenario is a commodity trading system, the first stored data may be commodity trading data.

[0047] S120: When a write execution condition is met, second storage data obtained by combining the plurality of first storage data written into the memory buffer is written into a hard disk, wherein the hard disk is a mechanical hard disk.

[0048] Among them, the write execution condition represents the condition for writing the first storage data in the memory buffer to the hard disk. In addition, in order to reduce the number of times the write operation is performed on the hard disk, the first storage data written to the memory buffer will be combined to obtain the second storage data, and then the operation of writing the second storage data to the hard disk is performed once, so that all the first storage data in the memory buffer that have not been written to the hard disk can be written to the hard disk. Exemplarily, when the write execution condition is met, the first storage data written to the memory buffer includes the first storage data a1, the first storage data a2, the first storage data a3 and the first storage data a4, and then the first storage data a1, the first storage data a2, the first storage data a3 and the first storage data a4 are combined to obtain the second storage data b1. Then, by writing the second storage data b1 to the hard disk once, the first storage data a1, the first storage data a2, the first storage data a3 and the first storage data a4 can all be written to the hard disk, without having to perform the write operation to the hard disk once for the first storage data a1, the first storage data a2, the first storage data a3 and the first storage data a4 respectively, thereby reducing the number of times the hard disk is written.

[0049] Wherein, as a method, when a write execution condition is met, writing the second storage data obtained by combining the multiple first storage data written to the memory buffer into the hard disk includes: when the write execution condition is met, combining the multiple first storage data written to the memory buffer into the second storage data based on a group commit method, and writing the second storage data to the hard disk. Wherein, the server or system component executing the data storage method can trigger the writing of the second storage data to the hard disk based on the group commit method through an fsync instruction.

[0050] S130: After the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored in the memory queue.

[0051] It should be noted that the purpose of writing the first storage data to the hard disk is for persistent storage, for example, so that data can be recovered from the hard disk after a power outage. When the first storage data is subsequently called, it will be called from the memory queue. In order to facilitate subsequent calls, after the second storage data is successfully written to the hard disk, the first storage data written to the memory buffer will be stored in the memory queue.

[0052] This embodiment provides a data storage method, which responds to a data storage request, first stores the first storage data requested to be stored in the hard disk in a memory buffer, and then, when the write execution condition is met, writes the second storage data obtained by combining the multiple first storage data written to the memory buffer into the hard disk, and then, when the second storage data is successfully written to the hard disk, stores the first storage data written to the memory buffer into the memory queue. Thus, by combining the multiple first storage data written to the memory buffer, it is possible to combine the multiple first storage data to obtain a second storage data, and then, by performing a data writing operation to the hard disk, the multiple first storage data combined to obtain the second storage data can be written to the hard disk, thereby reducing the number of times the hard disk is written. In addition, the mechanical hard disk locates the data write position based on the mechanical movement of the magnetic head during the data writing process. Therefore, when the number of times the hard disk is written is reduced, it is beneficial to reduce the number and movement distance of the mechanical movement of the magnetic head triggered by the hard disk, thereby improving the performance of writing data to the hard disk.

[0053] See also Figure 5 , Figure 5 FIG2 is a flow chart of a data storage method proposed in an embodiment of the present application, the method comprising:

[0054] S210: In response to a data storage request, storing first storage data requested for storage in a memory buffer, where the first storage data is data to be stored in a hard disk corresponding to the storage caller.

[0055] S220: When the write execution condition is met, obtain a splicing order corresponding to the plurality of first storage data written into the memory buffer.

[0056] In this embodiment, there are many ways to write the specific content of the execution condition.

[0057] As an approach, the write execution condition includes at least one of the following conditions: the quantity of the first stored data stored in the memory buffer satisfies a quantity threshold; the data volume of the first stored data stored in the memory buffer satisfies a data volume threshold; and the deadline of the current data write cycle is reached.

[0058] Optionally, the write execution condition may include that the number of first storage data stored in the memory buffer satisfies a quantity threshold. In this way, when the first storage data is written to the memory buffer, the number of the first storage data that has been written to the memory buffer and has not yet been written to the hard disk is updated accordingly. If the number satisfies the quantity threshold, it is determined that the write execution condition is satisfied. For example, if the quantity threshold is 3, then when the number of the first storage data that has been written to the memory buffer and has not yet been written to the hard disk is 2, when it is detected again that the first storage data is written to the memory buffer, the number is updated from 2 to 3. In this case, the number of the first storage data that has been written to the memory buffer and has not yet been written to the hard disk satisfies the quantity threshold 3, and then it is determined that the current write execution condition is satisfied, and the three first storage data are combined into one second storage data.

[0059] Optionally, the write execution condition may include that the amount of the first storage data stored in the memory buffer satisfies a data amount threshold. It should be noted that the data amount can be understood as the size of the storage space occupied by the first storage data. Exemplarily, if the memory buffer is written with first storage data a1 and first storage data a2, wherein the size of the storage space occupied by the first storage data a1 is 500KB and the size of the storage space occupied by the second storage data a2 is 600KB, then the number of first storage data stored in the memory buffer that has been written to the memory buffer and has not yet been written to the hard disk is 2, and the data amount is 1100KB. Correspondingly, the system combination or server will update the amount of the first storage data that has been written to the memory buffer and has not yet been written to the hard disk each time the first storage data is written to the memory buffer. If the updated data amount reaches the data amount threshold, it is determined that the write execution condition is satisfied. Exemplarily, the data amount threshold is 10MB. If the updated data amount is greater than 10MB, it is determined that the data amount threshold is satisfied, and then it is determined that the current write execution condition is satisfied.

[0060] Optionally, the write execution condition may include reaching the expiration time of the current data write cycle. It should be noted that the system component or server may periodically execute the operation of writing data to the hard disk. For example, the operation of writing data to the hard disk may be executed once every t seconds, such as Figure 6As shown, during the period from 2t to 3t, when the end time of the period is reached, the first stored data written to the memory buffer but not yet written to the hard disk includes the first stored data a5 and the first stored data a6. Furthermore, when the end time of the period from 2t to 3t is reached, the second stored data is obtained by combining the first stored data a5 and the first stored data a6. Similarly, when the end time of the period from 3t to 4t is reached, the second stored data is obtained by combining the first stored data a7, the first stored data a8, and the first stored data a9.

[0061] In addition, as described above, the write execution conditions may include not only one of the aforementioned conditions, but also multiple of the aforementioned conditions at the same time.

[0062] Optionally, the write execution condition may include the number of first stored data stored in the memory buffer satisfying a quantity threshold and the data volume of the first stored data stored in the memory buffer satisfying a data volume threshold. In this manner, it is necessary to simultaneously determine the number and data volume of the first stored data written to the memory buffer. If the number of the first stored data satisfies the quantity threshold and the data volume of the first stored data satisfies the data volume threshold, it is determined that the write execution condition is satisfied.

[0063] Optionally, the write execution condition may include that the amount of the first stored data stored in the memory buffer satisfies a quantity threshold and that the deadline of the current data write cycle has been reached. In this manner, it is necessary to simultaneously determine the amount of the first stored data written to the memory buffer and whether the deadline of the current data write cycle has been reached. Furthermore, when the amount of the first stored data written to the memory buffer satisfies the quantity threshold and the deadline of the current data write cycle has been reached, it is determined that the write execution condition is satisfied.

[0064] The conditions specifically included in the aforementioned write execution conditions are merely exemplary. For example, the write execution conditions may include a combination of any two of the aforementioned three conditions, or may include all three of the aforementioned conditions.

[0065] It should be noted that the triggering effect brought about by each specific condition in this embodiment will be different. For example, in this method based on the quantity threshold, it is necessary to wait until the number of first storage data written into the memory buffer meets the quantity threshold before determining that the write execution condition is met. After further research, the inventor found that if the data volume of each of the first storage data is generally large, it is still determined based on the quantity threshold whether the quantity threshold is met. This will cause the data volume of the second storage data obtained by combining when the execution condition is met to be larger, and it will take a relatively longer time to write the first storage data, which will cause a write delay for data with a later write order during the writing process.

[0066] For another example, in this method based on data volume threshold, the write operation to the hard disk will be triggered only when the amount of first storage data to be written to the memory buffer meets the data volume threshold. If the data volume of each of the first storage data is generally small, and the data volume threshold is still used to determine whether the write execution condition is met, a large amount of first storage data will need to be accumulated before the data volume threshold is reached, which will also cause a large delay in the first storage data previously stored in the memory buffer. For example, the first storage data a1, the first storage data a2, the first storage data a3...the first storage data a10 are stored in the memory buffer in sequence. If the write execution condition is met only when the first storage data a10 is written to the memory buffer, then the first storage data a1 written first will be stored with a large delay.

[0067] In order to make the data storage method provided by this embodiment more adaptable to the environment, the specific content of the write execution condition may be determined according to the amount of the first storage data requested to be stored.

[0068] As one approach, the specific content of the write execution condition may be determined according to the type of service to which the data storage method provided in this embodiment is applied.

[0069] It should be noted that for data of the same business type, the size of the data volume is relatively similar. For example, for user login services, the data stored may be the user's login account and the corresponding password, and the data volume corresponding to the login account and password is relatively small. In this way, it is possible to determine whether the write execution condition is met based on the quantity threshold. For another example, in some business scenarios, systems will dispatch data processing tasks to each other, and some data processing tasks that have not yet been executed will be stored, and what is stored may be the task identifier of the data processing task, and the data volume of the task identifier itself is relatively small. In this way, it is possible to determine whether the write execution condition is met based on the quantity threshold. Furthermore, for file storage services, what is stored are files, and the data volume of the files is relatively large compared to the aforementioned login account or task identifier. In this way, in order to avoid the storage delay problem shown above, it is possible to determine whether the write execution condition is met based on the data volume threshold.

[0070] Among them, optionally, a correspondence between the business type and the corresponding write execution condition can be established in advance, so that during the operation of the data storage method provided in this embodiment, after obtaining the business type from the currently deployed business scenario, the specific condition content included in the write execution condition can be determined based on the aforementioned correspondence. Exemplarily, the established correspondence includes business type p1 corresponding to write execution condition c1, business type p2 corresponding to write execution condition c1, business type p3 corresponding to write execution condition c2, and business type p4 corresponding to write execution condition c3. Then, when the business type is identified as p1, the determined write execution condition is write execution condition c1. When the business type is identified as p4, the determined write execution condition is write execution condition c3.

[0071] Optionally, if the data storage request carries a service identifier, in this embodiment, the system component and the server may identify the service type based on the service identifier carried in the data storage request. If the data storage request does not carry a service identifier, the service type may be identified based on the structure of the desired storage data (the first storage data).

[0072] As another way, the specific content of the conditions included in the write execution condition can be determined directly based on the size of the data volume of the storage data requested by the first storage data. Optionally, the data volume of the first storage data written to the memory buffer within a period of time can be counted, and the average data volume of each first storage data can be calculated. If the average data volume is less than the average threshold, it can be determined based on the quantity threshold whether the write execution condition is met. Conversely, if the average data volume is greater than the average threshold, it can be determined based on the data volume threshold whether the write execution condition is met. Exemplarily, the first storage data written to the memory buffer within a period of time includes first storage data a1, first storage data a2, first storage data a3...first storage data a10, a total of 10 first storage data, then the sum of the data volumes of the 10 first storage data can be divided by 10 to obtain the average data volume.

[0073] It should be noted that in this method, it may be that in the early stage (for example, when the average data volume has not been calculated for the first time) it is not yet determined how to determine the specific conditions included in the write execution conditions. In this case, the default method of determining whether the write execution conditions are met can be used first. After the average data volume is calculated to determine the corresponding method of determining whether the write execution conditions are met, the write execution conditions obtained based on the average data volume can be used to execute subsequent steps.

[0074] Furthermore, the aforementioned two methods based on the business type and the size of the requested storage data can be combined to determine the conditional content included in the write execution condition. It should be noted that in this method of determining the conditional content included in the write execution condition based on the business type, the business type can be identified when the first storage data is first obtained, and the conditional content included in the write execution condition can be determined more immediately. However, in this method based on the size of the requested storage data, a certain amount of first storage data needs to be obtained before the conditional content included in the write execution condition can be determined. Then as a way, such as Figure 7 In this way, there are two stages in the operation of the data storage method provided in this embodiment, namely Figure 7 The first and second stages are shown in . The first stage is the stage where the data processing method starts to run. In this stage, because a sufficient amount of first storage data has not yet been obtained, the average data volume has not yet been calculated based on the data volume of the first storage data to determine the specific conditions included in the write execution condition. In order to ensure that the first storage data in the memory buffer can still be smoothly written to the hard disk, the specific conditions included in the write execution condition will be determined according to the business type in the first stage. Figure 7 As shown, tk The average data volume is calculated for the first time, and the time for obtaining the specific condition content included in the write execution condition is determined based on the average data volume calculated for the first time. Then at t k After that time, the write execution condition will be determined based on the average data amount.

[0075] When it is determined that the write execution condition is met, the first stored data written to the memory buffer and not yet written to the hard disk can be spliced to obtain the second stored data. Optionally, when splicing the first stored data, since there may be multiple first stored data, a splicing order for each first stored data can be determined first, so that the splicing can be performed based on the corresponding splicing order. In this embodiment, there can be multiple ways to determine the splicing order.

[0076] As a way, obtaining the splicing order corresponding to the multiple first storage data written into the memory buffer includes: obtaining the business type corresponding to the first storage data written into the memory buffer; and determining the splicing order corresponding to the multiple first storage data written into the memory buffer based on the business type. It should be noted that the business type corresponding to the first storage data can be understood as the business type of the business that generates the first storage data. The data storage method provided in the embodiment of the present application can be run in a business scenario. In the same business scenario, the received first storage data is generated by the same business, and the business type corresponding to the first storage data is the same. In one way, the data storage method provided in the embodiment of the present application can support multiple types of business at the same time, so the received first storage data can be generated by different businesses, and the business type corresponding to the received first storage data can be different.

[0077] Optionally, the first storage data written into the memory buffer may be data to be stored in the hard disk corresponding to the same business, or may be data to be stored in the hard disk corresponding to different businesses. Exemplarily, when the write execution condition is met, the first storage data written into the memory buffer and not yet written to the hard disk includes first storage data a1, first storage data a2, first storage data a3, and first storage data a4, wherein the first storage data a1 and the first storage data a2 may belong to storage data generated under the same business, and the first storage data a3 and the first storage data a4 may belong to storage data generated under the same business.

[0078] Among them, the storage priorities corresponding to different services may be different. Optionally, the splicing order of each first stored data can be determined based on the priority of the service type corresponding to the first stored data, wherein the splicing order corresponding to the first stored data with a higher priority of the corresponding service type is higher. Figure 8 As shown in the figure, the first stored data a1 is the first in the splicing order, followed by the first stored data a2, then the first stored data a3, and finally the first stored data a4. The second stored data obtained by splicing is shown in the figure, where the direction indicated by the dotted arrow is the direction of the front. It should be noted that in the embodiment of the present application, the front can be understood as the direction close to the start of writing. When writing the second stored data to the hard disk, the first stored data with the first splicing order will be written to the hard disk first.

[0079] As another way, obtaining the splicing order corresponding to the multiple first storage data written into the memory buffer includes: obtaining the write time of the first storage data into the memory buffer; and determining the splicing order corresponding to the multiple first storage data written into the memory buffer based on the write time. In this way, the write time of each first storage data written into the memory buffer can be recorded, and then in the process of determining the splicing order corresponding to the multiple first storage data written into the memory buffer based on the write time, the first storage data whose corresponding write time is longer from the current moment is configured with a splicing order that is closer to the front. Among them, the current moment is the moment to start determining the splicing order of the first storage data, so the longer the corresponding write time is from the current moment, it can be understood that the buffering time in the memory buffer is longer. For example, the buffering time of the first storage data a1 from being written into the memory buffer to the current moment is 1 second, and the buffering time of the first storage data a2 from being written into the memory buffer to the current moment is 0.5 seconds. Then the buffering time corresponding to the first storage data a1 is longer than the buffering time corresponding to the first storage data a2, which means that the time between the writing time of the first storage data a1 and the current moment is longer than the time between the writing time of the first storage data a2 and the current moment.

[0080] It should be noted that in the aforementioned method of determining the splicing order based on the business type, there may be multiple first storage data corresponding to the same business type. In this case, for the first storage data with the same corresponding business type, the corresponding splicing order can be determined in combination with the write time. Optionally, for the first storage data with the same corresponding business type, the longer the corresponding write time is from the current moment, the higher the corresponding splicing order. For example, taking the first storage data including the first storage data a1, the first storage data a2, the first storage data a3 and the first storage data a4 as an example, if the business types corresponding to the first storage data a1 and the first storage data a2 are both business type e1, the business types corresponding to the first storage data a3 and the first storage data a4 are both e2, and the priority corresponding to the business type e1 is higher than the priority corresponding to the business type e1. Furthermore, the length of time from the write time corresponding to the first storage data a2 to the current moment is longer than the length of time from the write time corresponding to the first storage data a1 to the current moment, and the length of time from the write time corresponding to the first storage data a3 to the current moment is longer than the length of time from the write time corresponding to the first storage data a4 to the current moment. Then, based on the business type, it is first determined that the splicing order of the first storage data a1 and the first storage data a2 is earlier than the splicing order of the first storage data a3 and the first storage data a4. Then, combined with the write time, it is determined that the splicing order of the first storage data a2 is earlier than the first storage data a1, and the splicing order of the first storage data a3 is earlier than the first storage data a4. Then, the splicing order determined from front to back is first storage data a2, first storage data a1, first storage data a3 and first storage data a4.

[0081] S230: Based on the splicing order, the plurality of first storage data written into the memory buffer are sequentially spliced to obtain second storage data, wherein when writing the second storage data into the hard disk, the first storage data with a higher splicing order will be given priority in the write operation.

[0082] In the process of writing the data in the memory buffer to the hard disk, the write operation can be performed based on the storage instruction. If the first storage data is not spliced and the write operation to the hard disk is performed directly, the storage instruction will be executed once for each first storage data. Each storage instruction can have an instruction header and an instruction tail, and the actual stored data will be between the instruction header and the instruction tail. Take the first storage data a1 and the first storage data a2 as an example. If splicing is not performed, such as Figure 9 As shown in the upper part, the storage instruction will be executed once for the first storage data a1 and the first storage data a2 respectively. If the first storage data a1 and the first storage data a2 are spliced, then Figure 8As shown in the lower part, it is only necessary to execute the storage instruction once to write both the first storage data a1 and the first storage data a2 into the hard disk.

[0083] S240: Writing the second stored data into the hard disk.

[0084] S250: After the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored in the memory queue.

[0085] As a method, when first storage data is detected, after storing the first storage data in the memory buffer, it also includes: putting the storage caller that generates the first write data into a blocked state; when the write execution condition is met, after writing the second storage data obtained by combining multiple first storage data written into the memory buffer into the hard disk, it also includes: when the second storage data is successfully written to the hard disk, the storage caller that is in a blocked state releases the data blocking state to return a message of successful write.

[0086] Among them, the storage caller in a blocked state can be understood as a state of waiting for the storage result, and then after the second storage data is written to the hard disk, the system component or server that performs the write operation can release the blocking state of the data caller, and then return a message of successful write to the storage caller. It should be noted that the system component or server can allocate a thread to each storage caller that sends a data storage request to perform the operation of writing the corresponding first storage data to the memory buffer, so the aforementioned placing the storage caller that generates the first write data in a blocked state can be understood as placing the thread corresponding to the storage caller that generates the first write data in a blocked state, and correspondingly, releasing the data blocking state of the storage caller in a blocked state can be understood as releasing the blocking state of the thread corresponding to the storage caller in a blocked state.

[0087] For example, Figure 10 As shown, after the first storage data corresponding to each of the storage callers u1, storage caller u2 and storage caller u3 is written into the memory buffer 60, the storage callers u1, storage caller u2 and storage caller u3 are all in a blocked state. After the second storage data b1 based thereon is successfully written into the file system 70 in the hard disk, the storage callers u1, storage caller u2 and storage caller u3 will be triggered to unblock the state.

[0088] As a method, after the second storage data is successfully written into the hard disk, storing the first storage data written into the memory buffer into the memory queue further includes: deleting the first storage data written into the memory buffer from the memory buffer.

[0089] As a method, after the second storage data is successfully written to the hard disk, the first storage data written to the memory buffer is stored in the memory queue, and the method further includes: after the first storage data is taken out from the memory queue, the first storage data taken out from the memory queue is deleted from the hard disk. Actively deleting the first storage data written to the memory buffer from the memory buffer can help to clean up useless data in the memory buffer more promptly, so as to reduce the power consumption consumed to maintain data storage. Among them, useless data can be understood as data that has been written to the hard disk. For example, Figure 11 As shown, for the aforementioned Figure 10 The first stored data a1, the first stored data a2, and the first stored data a3 shown in the figure are written to the memory queue 80 after being written from the memory buffer to the hard disk. When data is retrieved from the memory queue 80, for example, the retrieved first stored data a1, the first stored data a1 is also deleted from the file system 70, thereby reclaiming the occupied hard disk space.

[0090] This embodiment provides a data storage method, which combines multiple first storage data written to a memory buffer to obtain a second storage data. This allows the multiple first storage data to be combined to obtain a second storage data, thereby achieving a single data write operation to the hard disk. Furthermore, a mechanical hard disk locates the data write position based on the mechanical movement of the magnetic head during data writing. Therefore, while reducing the number of hard disk writes, it is beneficial to reduce the number and distance of mechanical movement of the magnetic head triggered by the hard disk, thereby improving the performance of writing data to the hard disk. Furthermore, in this embodiment, when splicing the first storage data, the splicing order of each first storage data is first obtained so that the splicing is performed according to the splicing order of each first storage data to improve the flexibility of the combination process. Furthermore, in this embodiment, there can be multiple ways to determine the splicing order, which also allows the process of combining the second storage data to better adapt to the current actual environment, thereby improving the environmental adaptability of the data storage method.

[0091] See also Figure 12 , Figure 12 FIG2 is a flow chart of a data storage method proposed in an embodiment of the present application, the method comprising:

[0092] S310: In response to a data storage request, storing first storage data requested for storage in a memory buffer, where the first storage data is data to be stored in a hard disk corresponding to the storage caller.

[0093] S320: When first storage data is stored in the memory buffer, a splicing order corresponding to the plurality of first storage data written into the memory buffer is obtained.

[0094] In this embodiment, unlike the aforementioned embodiment, in the aforementioned embodiment, when it is detected that the write execution condition is met, the splicing order of each first storage data is obtained to perform the splicing operation, while in this embodiment, when the first storage data is written to the memory buffer, the splicing order can be configured for the written first storage data and the splicing operation can be performed.

[0095] S330: Sequentially splicing the first storage data stored in the memory buffer based on the splicing order, wherein when writing the second storage data to the hard disk, the first storage data with an earlier splicing order will be given priority in the write operation.

[0096] In this embodiment, the splicing operation can be performed immediately after the splicing order of the first stored data is obtained, rather than waiting until the write execution condition is met, thereby improving the efficiency of writing to the hard disk. In this manner, the first stored data written to the memory buffer later does not necessarily have a later splicing order.

[0097] Then, as a method, when the first storage data is written to the memory buffer, the splicing order of all the first storage data written previously can also be updated, and the splicing can be performed after the update. For example, if when the first storage data a3 is received, the first storage data a1 and the first storage data a2 have been received previously, and the splicing has been performed in the splicing order of the first storage data a1 first and the first storage data a2 later, then when the first storage data a3 is received, the splicing order of the first storage data a1 and the first storage data a2 will be re-determined. If the splicing order of the first storage data a3 is determined to be before the first storage data a2, the splicing will be performed in the order of the first storage data a1, the first storage data a3, and the first storage data a2.

[0098] As another way, if the number of first storage data is relatively large, the splicing order of all the previous first storage data is updated every time the first storage data is written to the memory buffer, which will result in a large amount of data calculation. In order not to increase the amount of data calculation too much, when the first storage data is written, the written first storage data can be compared with the splicing order of the first storage data at the end of the current splicing order, and updated according to the comparison result. For example, the first storage data a1 and the first storage data a2 have been received before, and have been spliced in the splicing order of the first storage data a1 in front and the first storage data a2 in the back, then when the first storage data a3 is received, it is determined that the first storage data at the end of the current splicing order is the first storage data a2, and the splicing order of the first storage data a3 and the first storage data a2 will be re-compared.

[0099] S340: When a write execution condition is met, the second storage data obtained by splicing is written into a hard disk, where the hard disk is a mechanical hard disk.

[0100] S350: After the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored in the memory queue.

[0101] This embodiment provides a data storage method, which combines multiple first storage data written to a memory buffer to obtain a second storage data. This allows the multiple first storage data to be combined to obtain the second storage data by performing a single write operation to the hard disk, thereby reducing the number of write operations to the hard disk. Furthermore, in this embodiment, when the first storage data is written to the memory buffer, the corresponding splicing order is obtained for splicing. When the write execution condition is met, the write operation to the hard disk can be directly executed without performing the splicing operation, thereby improving the write efficiency.

[0102] See also Figure 13 , Figure 13 FIG2 is a flow chart of a data storage method proposed in an embodiment of the present application, the method comprising:

[0103] S410: In response to a data storage request in the current data storage cycle, storing first storage data requested to be stored in a memory buffer.

[0104] S420: When the write execution condition of the current data storage cycle is met, second storage data obtained by combining the plurality of first storage data written into the memory buffer in the current data storage cycle is written into the hard disk.

[0105] Optionally, in this embodiment, the first storage data combination is performed periodically. The period may be based on time, quantity, or data volume. After the splicing operation is performed when the write execution conditions of the current data storage period are met, the next data storage period begins. For example, the period may be 10 seconds apart, or 3 first storage data may be written to the memory buffer.

[0106] S430: When the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored in the memory queue.

[0107] This embodiment provides a data storage method, which combines multiple first storage data written to the memory buffer to obtain a second storage data. Then, by performing a data write operation to the hard disk once, the multiple first storage data combined to obtain the second storage data can be written to the hard disk, thereby reducing the number of write operations to the hard disk. In addition, during the data writing process, the mechanical hard disk locates the data write position based on the mechanical movement of the magnetic head. Therefore, when the number of write operations to the hard disk is reduced, it is beneficial to reduce the number of times and the movement distance of the mechanical movement of the magnetic head triggered by the hard disk, thereby improving the performance of writing data to the hard disk.

[0108] See also Figure 14 , Figure 14 FIG2 is a flow chart of a data storage method proposed in an embodiment of the present application, the method comprising:

[0109] S510: Receive the assigned task.

[0110] Optionally, the task may be a data processing task.

[0111] S520: Generate a data storage request corresponding to the task.

[0112] It should be noted that processing tasks requires consuming processing resources. If processing resources are tight or insufficient, received tasks may not be processed in a timely manner. In this case, tasks that cannot be processed in a timely manner may be persistently stored. Optionally, the data storage request is a data storage request for persistently storing tasks that cannot be processed in a timely manner.

[0113] S530: In response to the data storage request, store the task requested to be stored as first storage data in the memory buffer.

[0114] S540: When a write execution condition is met, second storage data obtained by combining the plurality of first storage data written into the memory buffer is written into a hard disk, wherein the hard disk is a mechanical hard disk.

[0115] S550: After the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored in the memory queue.

[0116] Among them, when the task stored in the memory queue can be processed, the task to be executed can be taken out from the memory queue first. When the task to be executed is taken out from the memory queue, the task to be executed in the memory queue will also be deleted from the hard disk.

[0117] The data storage method provided in this embodiment can store the received task as the first storage data in the memory buffer, and then combine multiple tasks to obtain the second storage data when the write execution condition is met, thereby realizing the one-time writing of multiple tasks to the hard disk, thereby improving the performance of writing to the hard disk during the process of persistent storage of tasks.

[0118] It should be noted that in one environment configuration, 4KB of data is written to the hard disk each time, and eight users (storage callers) simultaneously call and execute multiple write operations to the hard disk. The IOPS (Input / Output Operations Per Second) of the related persistent queue write interface is 20, and the maximum latency of the write request deteriorates to 40 seconds.

[0119] Under the same environmental configuration, the data storage method provided by the basic application embodiment has 8 users (storage callers) calling multiple write operations to the hard disk simultaneously. The IOPS of the persistent queue write interface is 190, and the maximum delay of the write request is 393 milliseconds. 64 users (storage callers) calling multiple write operations to the hard disk simultaneously, the IOPS of the persistent queue write interface is 1104, and the maximum delay of the write request is 500 milliseconds. 1024 users (storage callers) calling multiple write operations to the hard disk simultaneously, the IOPS of the persistent queue write interface is 9402, and the maximum delay of the write request is 532 milliseconds.

[0120] See also Figure 15 , Figure 15 FIG. 8 is a data storage device 800 according to an embodiment of the present application. The device 800 includes:

[0121] The data buffer unit 810 is configured to store the first storage data requested for storage in the memory buffer in response to the data storage request, where the first storage data is the data to be stored in the hard disk corresponding to the storage caller;

[0122] The persistent write unit 820 is configured to write the second stored data obtained by combining the plurality of first stored data written into the memory buffer into the hard disk when a write execution condition is met, wherein the hard disk is a mechanical hard disk;

[0123] The memory writing unit 830 is configured to store the first storage data written into the memory buffer into the memory queue after the second storage data is successfully written into the hard disk.

[0124] As a method, the persistent write unit 820 is specifically used to combine multiple first storage data written into the memory buffer into second storage data based on the group submission method when the write execution condition is met, and write the second storage data into the hard disk.

[0125] As a method, the persistent write unit 820 is specifically used to obtain the splicing order corresponding to multiple first storage data written into the memory buffer when the write execution condition is met; based on the splicing order, the multiple first storage data written into the memory buffer are spliced in sequence to obtain the second storage data, wherein, when writing the second storage data into the hard disk, the first storage data with a higher splicing order will have a higher priority in executing the write operation; and the second storage data is written into the hard disk.

[0126] As a method, the persistent write unit 820 is specifically used to obtain the splicing order corresponding to multiple first storage data written into the memory buffer when first storage data is stored into the memory buffer; based on the splicing order, the first storage data stored into the memory buffer are spliced in sequence, wherein, when writing the second storage data into the hard disk, the first storage data with a higher splicing order will have a higher priority in executing the write operation; when the write execution condition is met, the second storage data obtained by splicing will be written into the hard disk.

[0127] Optionally, the persistent writing unit 820 is specifically configured to obtain a business type corresponding to the first storage data written into the memory buffer; and determine a splicing order corresponding to the plurality of first storage data written into the memory buffer based on the business type.

[0128] Optionally, the persistent write unit 820 is specifically used to obtain the write time of the first storage data written to the memory buffer; based on the write time, determine the splicing order corresponding to the multiple first storage data written to the memory buffer, wherein the first storage data with an earlier write time has an earlier corresponding splicing order.

[0129] As one approach, the data buffer unit 810 is specifically configured to, in response to a data storage request during the current data storage cycle, store the requested first storage data in the memory buffer. In this approach, the persistent write unit 820 is specifically configured to, when a write execution condition of the current data storage cycle is met, write the second storage data obtained by combining the plurality of first storage data written to the memory buffer during the current data storage cycle to the hard disk.

[0130] Optionally, the write execution condition includes at least one of the following conditions: the quantity of the first stored data stored in the memory buffer meets the quantity threshold; the data volume of the first stored data stored in the memory buffer meets the data volume threshold; and the deadline of the current data write cycle is reached.

[0131] like Figure 16 As shown, the apparatus 800 further includes a blocking control unit 840 for, upon detecting the presence of first storage data, storing the first storage data in the memory buffer, and then placing the storage caller generating the first write data in a blocking state. The blocking control unit 840 is further configured to, after writing second storage data obtained by combining multiple first storage data written into the memory buffer into the hard disk, release the data blocking state of the storage caller in the blocking state and return a message indicating a successful write after the second storage data is successfully written into the hard disk.

[0132] The storage data management unit 850 is configured to, after the second storage data is successfully written to the hard disk, store the first storage data written to the memory buffer in the memory queue and then delete the first storage data written to the memory buffer from the memory buffer. The storage data management unit 850 is further configured to, after the second storage data is successfully written to the hard disk, store the first storage data written to the memory buffer in the memory queue and then, when the first storage data is retrieved from the memory queue, delete the first storage data retrieved from the memory queue from the hard disk.

[0133] The present application provides a data storage device, which responds to a data storage request, first stores the first storage data requested to be stored in the hard disk into a memory buffer, and then when the write execution condition is met, writes the second storage data obtained by combining the multiple first storage data written to the memory buffer into the hard disk, and then when the second storage data is successfully written to the hard disk, stores the first storage data written to the memory buffer into the memory queue. Thus, by combining the multiple first storage data written to the memory buffer, it is possible to combine the multiple first storage data to obtain a second storage data, and then realize the operation of writing data to the hard disk once, and the multiple first storage data combined to obtain the second storage data can be written to the hard disk, reducing the number of times the hard disk is written. In addition, the mechanical hard disk locates the data write position based on the mechanical movement of the magnetic head during the data writing process. Then, when the number of times the hard disk is written is reduced, it is beneficial to reduce the number and movement distance of the mechanical movement of the magnetic head triggered by the hard disk, thereby improving the performance of writing data to the hard disk.

[0134] It should be noted that the device embodiment in this application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment and will not be repeated here.

[0135] The following will be combined Figure 17 An electronic device provided by this application is described.

[0136] See also Figure 17 Based on the above data storage method, the present application also provides another electronic device 200 including a processor 104 capable of executing the above data storage method. The electronic device 200 also includes a memory 104 and a network module 106. The memory 104 stores a program capable of executing the content of the above embodiments, and the processor 102 can execute the program stored in the memory 104.

[0137] The processor 102 utilizes various interfaces and circuits to connect various components within the electronic device 200. It executes instructions, programs, code sets, or instruction sets stored in the memory 104, and accesses data stored in the memory 104 to perform various functions and process data within the electronic device 200. Optionally, the processor 102 can be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 102 can integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily handles the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem handles wireless communications. It is understood that the modem can also be implemented independently of the processor 102 via a separate communications chip.

[0138] The memory 104 may include random access memory (RAM) or read-only memory (ROM). The memory 104 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 104 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the terminal 100 during use (such as a phone book, audio and video data).

[0139] The network module 106 is used to receive and transmit electromagnetic waves, converting them into electrical signals, thereby communicating with a communications network or other devices, such as an audio playback device. The network module 106 may include various existing circuit components for performing these functions, such as an antenna, a radio frequency transceiver, a digital signal processor, an encryption / decryption chip, a subscriber identity module (SIM) card, memory, and the like. The network module 106 can communicate with various networks, such as the Internet, an intranet, or a wireless network, or with other devices via a wireless network. These wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. For example, the network module 106 may exchange information with a base station.

[0140] Please refer to Figure 18 , which shows a block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 1100 stores program code, which can be called by a processor to execute the method described in the above method embodiment.

[0141] Computer-readable storage medium 1100 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, a hard disk, or ROM. Alternatively, computer-readable storage medium 1100 may include non-transitory computer-readable storage medium. Computer-readable storage medium 1100 has storage space for program code 1110 for executing any of the method steps described above. This program code can be read from or written to one or more computer program products. Program code 1110 may be compressed, for example, in a suitable format.

[0142] The present application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the above-mentioned data storage method.

[0143] In summary, the present application provides a data storage method, device, electronic device and storage medium, which responds to a data storage request, stores the first storage data requested to be stored in the hard disk first in the memory buffer, and then when the write execution condition is met, writes the second storage data obtained by combining the multiple first storage data written to the memory buffer into the hard disk, and then when the second storage data is successfully written to the hard disk, stores the first storage data written to the memory buffer into the memory queue. Thus, by combining the multiple first storage data written to the memory buffer, it is possible to combine the multiple first storage data to obtain a second storage data, and then realize the operation of writing data to the hard disk once, and the multiple first storage data combined to obtain the second storage data can be written to the hard disk, reducing the number of times the hard disk is written. In addition, the mechanical hard disk locates the data write position based on the mechanical movement of the magnetic head during the data writing process. If the number of times the hard disk is written is reduced, it is beneficial to reduce the number and movement distance of the mechanical movement of the magnetic head triggered by the hard disk, thereby improving the performance of writing data to the hard disk.

[0144] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A data storage method, characterized in that: The method comprises: In response to a data storage request, storing first storage data requested for storage in a memory buffer, and placing a storage caller of the first storage data in a blocked state, wherein the first storage data is data corresponding to the storage caller and to be stored in a hard disk; wherein the data storage request is initiated when a task cannot be processed in a timely manner, and the first storage data is a task that cannot be processed in a timely manner; When a write execution condition is met, writing second storage data obtained by combining the plurality of first storage data written into the memory buffer into the hard disk, wherein the hard disk is a mechanical hard disk; When the second storage data is successfully written into the hard disk, the first storage data written into the memory buffer is stored in the memory queue, so that the storage caller in the blocked state is released from the blocked state, a write success message is returned, and the first storage data is deleted from the memory buffer; When the tasks stored in the memory queue need to be processed, the tasks to be executed are taken out from the memory queue and deleted from the hard disk.

2. The method according to claim 1, characterized in that When the write execution condition is met, writing the second storage data obtained by combining the plurality of first storage data written into the memory buffer into the hard disk comprises: When a write execution condition is met, the plurality of first storage data written into the memory buffer are combined into second storage data based on a group submission method, and the second storage data is written into the hard disk.

3. The method according to claim 1, characterized in that When the write execution condition is met, writing the second storage data obtained by combining the plurality of first storage data written into the memory buffer into the hard disk comprises: When the write execution condition is met, obtaining a splicing order corresponding to the plurality of first storage data written into the memory buffer; Based on the splicing order, the plurality of first storage data written into the memory buffer are sequentially spliced together to obtain second storage data, wherein when writing the second storage data into the hard disk, the first storage data with a higher splicing order will be given higher priority in the write operation; The second stored data is written into the hard disk.

4. The method according to claim 1, wherein When the write execution condition is met, writing the second storage data obtained by combining the plurality of first storage data written into the memory buffer into the hard disk comprises: When first storage data is stored in the memory buffer, obtaining a splicing order corresponding to the plurality of first storage data written into the memory buffer; Based on the splicing order, the first storage data stored in the memory buffer are sequentially spliced, wherein when writing the second storage data to the hard disk, the first storage data with a higher splicing order will be given priority in the write operation; When a write execution condition is met, the second storage data obtained by the splicing is written into the hard disk.

5. The method according to claim 3 or 4, characterized in that The obtaining of the splicing order corresponding to the plurality of first storage data written into the memory buffer includes: Obtaining a service type corresponding to the first storage data written into the memory buffer; Based on the service type, a splicing order corresponding to the plurality of first storage data written into the memory buffer is determined.

6. The method according to claim 3 or 4, characterized in that The obtaining of the splicing order corresponding to the plurality of first storage data written into the memory buffer includes: Obtaining a writing time when the first storage data is written into the memory buffer; Based on the writing time, a splicing order corresponding to the plurality of first storage data written into the memory buffer is determined, wherein the first storage data with an earlier writing time has an earlier corresponding splicing order.

7. The method according to claim 1, characterized in that The storing, in response to the data storage request, the first storage data requested for storage into the memory buffer, comprises: storing, in response to the data storage request in the current data storage cycle, the first storage data requested for storage into the memory buffer; When the write execution condition is met, the second storage data obtained by combining the multiple first storage data written into the memory buffer is written into the hard disk, including: when the write execution condition of the current data storage cycle is met, the second storage data obtained by combining the multiple first storage data written into the memory buffer in the current data storage cycle is written into the hard disk.

8. The method according to any one of claims 1 to 4 and 7, characterized in that The write execution condition includes at least one of the following conditions: The amount of the first stored data stored in the memory buffer satisfies a quantity threshold; The amount of the first stored data stored in the memory buffer satisfies a data amount threshold; as well as The deadline for the current data write cycle has arrived.

9. A data storage device, characterized in that The device comprises: a data buffer unit, configured to store first storage data requested for storage in a memory buffer in response to a data storage request, wherein the first storage data is data to be stored in a hard disk corresponding to a storage caller; wherein the data storage request is initiated when a task cannot be processed in a timely manner, and the first storage data is the task that cannot be processed in a timely manner; a persistent write unit, configured to write second storage data obtained by combining the plurality of first storage data written into the memory buffer into the hard disk when a write execution condition is met, wherein the hard disk is a mechanical hard disk; A memory writing unit, configured to store the first storage data written into the memory buffer into a memory queue after the second storage data is successfully written into the hard disk; a blocking control unit, configured to place a storage caller of the first storage data in a blocked state after storing the first storage data in the memory buffer, and further configured to write the second storage data obtained by combining multiple first storage data written into the memory buffer into the hard disk, and when the second storage data is successfully written into the hard disk, release the blocked state of the storage caller and return a message indicating a successful write; A storage data management unit is used to store the first storage data written into the memory buffer into a memory queue after the second storage data is successfully written into the hard disk, and then delete the first storage data from the memory buffer; and is also used to take out the task to be executed from the memory queue and delete the task to be executed from the hard disk when the task stored in the memory queue needs to be processed.

10. The device according to claim 9, characterized in that The persistent writing unit is specifically configured to combine the plurality of first storage data written into the memory buffer into second storage data based on a group submission method when a write execution condition is met, and write the second storage data into the hard disk.

11. The device according to claim 9, characterized in that The persistent write unit is specifically used to obtain the splicing order corresponding to the multiple first storage data written into the memory buffer when the write execution condition is met; based on the splicing order, the multiple first storage data written into the memory buffer are sequentially spliced to obtain the second storage data, wherein, when writing the second storage data into the hard disk, the first storage data with a higher splicing order will have a higher priority in executing the write operation; and the second storage data is written into the hard disk.

12. The device according to claim 9, characterized in that The persistent write unit is specifically used to obtain a splicing order corresponding to multiple first storage data written into the memory buffer when first storage data is stored into the memory buffer; based on the splicing order, the first storage data stored into the memory buffer are sequentially spliced, wherein, when writing the second storage data into the hard disk, the first storage data with a higher splicing order will have a higher priority in executing the write operation; when the write execution condition is met, the second storage data obtained by the splicing is written into the hard disk.

13. The device according to claim 11 or 12, characterized in that The persistent writing unit is specifically configured to obtain a business type corresponding to the first storage data written into the memory buffer; and based on the business type, determine a splicing order corresponding to the plurality of first storage data written into the memory buffer.

14. The device according to claim 11 or 12, characterized in that The persistent write unit is specifically used to obtain the write time of the first storage data written into the memory buffer; based on the write time, determine the splicing order corresponding to the multiple first storage data written into the memory buffer, wherein the first storage data with an earlier write time has an earlier corresponding splicing order.

15. The device according to claim 9, characterized in that The data buffer unit is specifically configured to store the first storage data requested to be stored in the memory buffer in response to the data storage request during the current data storage cycle; The persistent writing unit is specifically configured to write the second storage data obtained by combining the plurality of first storage data written into the memory buffer in the current data storage cycle into the hard disk when the write execution condition of the current data storage cycle is met.

16. The device according to any one of claims 9 to 12 and 15, characterized in that The write execution condition includes at least one of the following conditions: The amount of the first stored data stored in the memory buffer satisfies a quantity threshold; The amount of the first stored data stored in the memory buffer satisfies a data amount threshold; as well as The deadline for the current data write cycle has arrived.

17. An electronic device, characterized in that: The device comprises a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the method of claims 1-8.

18. A computer-readable storage medium, characterized in that The computer-readable storage medium stores program code, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 8 is executed.

19. A computer program product, characterized in that The method comprises computer instructions, which implement the method according to any one of claims 1 to 8 when executed by a processor.

Citation Information

Patent Citations

  • File safety storage and content protection method

    CN108399099A

  • Data processing method, device and equipment and storage medium

    CN109656487A