Data storage method and device, electronic equipment, and storage medium
By identifying the target storage sector and updating the status information in the electricity meter data storage, the problems of EEPROM write corruption and low search efficiency are solved, achieving efficient data storage and retrieval.
Patent Information
- Application Number
- CN202211713316.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2042-12-29
AI Technical Summary
Existing storage solutions, when dealing with high recording frequency and large data volume, suffer from EEPROM write failures and low lookup efficiency, failing to meet the storage needs of large amounts of data in electricity meters.
By obtaining the target storage sector of the data to be stored, determining the target storage location based on the status information of the data already stored in the sector, and updating the status information after storage, the dependence on pointer information is reduced and the search efficiency is improved.
It improves the efficiency of data storage retrieval, supports more frequent storage operations, reduces storage complexity, and reduces the number of additional data writing operations.
Smart Images

Figure CN115905307B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, in particular to a data storage method and device, electronic equipment and computer readable storage medium. BACKGROUND
[0002] At present, as a data node, an electric energy meter generates data every moment and saves the data in the format of (time stamp + collected data). The data generated by the electric energy meter is usually saved for 1 year or even 3 years. For an embedded system, the data volume is large. When needed, the data stored by the collection system is read by time period, for example, the data from 2022 / 08 / 03 00:00:00 to 2022 / 08 / 04 00:00:00 is read.
[0003] The current storage scheme generally saves the pointer of a FIFO (First Input First Output) in an EEPROM (Electrically Erasable Programmable Read-Only Memory) and saves the data in a DataFlash (data flash memory). This storage scheme involves two storage media. When reading, the collection system adopts a traversal method to find data, and the target storage scheme can only meet the condition of low recording frequency and small total data volume. In the case of high recording frequency and large data volume, the EEPROM may be damaged and the search efficiency is low. SUMMARY
[0004] To solve the above technical problems, the embodiments of the present application provide a data storage method and device, electronic equipment and computer readable storage medium, which are aimed at solving the technical problem of low search efficiency of stored data.
[0005] Other characteristics and advantages of the present application will become apparent from the following detailed description, or will be learned by practice of the present application.
[0006] According to an aspect of an embodiment of the present application, a data storage method is provided, comprising:
[0007] obtaining a target storage sector to which the to-be-stored data is to be stored;
[0008] determining a target storage position of the to-be-stored data in the target storage sector based on state information of the stored data in the target storage sector; wherein the state information is used to represent the state of the stored data;
[0009] storing the to-be-stored data to the target storage position in the target storage sector;
[0010] updating state information of the stored data in the target storage sector to which the to-be-stored data is stored.
[0011] Further, the target storage sector to which the to-be-stored data is stored is obtained, including:
[0012] The storage area corresponding to the to-be-stored data is obtained, and the storage area includes a plurality of storage sectors.
[0013] The target storage sector is determined from the plurality of storage sectors based on the state information of the stored data in the plurality of storage sectors.
[0014] Further, the target storage sector is determined from the plurality of storage sectors based on the state information of the stored data in the plurality of storage sectors, including:
[0015] For each storage sector, a storage location in the storage sector is traversed based on the state information of the stored data in the storage sector.
[0016] The storage sector in which the latest stored data is located is determined based on the traversal condition.
[0017] The target storage sector is determined from the plurality of storage sectors based on the storage sector in which the latest stored data is located.
[0018] Further, the storage sector in which the latest stored data is located is determined based on the traversal condition, including:
[0019] If the state information of the last storage location in the traversed storage sector represents a null state, the storage sector in which the state information of the last storage location represents the null state is taken as a candidate storage sector.
[0020] It is detected whether the state information of a storage location in the candidate storage sector represents a current state.
[0021] If so, the candidate storage sector in which the state information of the storage location represents the current state is taken as the storage sector in which the latest stored data is located.
[0022] If not, the storage sector in which the state information of the last storage location in the traversed storage sector represents the current state is taken as the storage sector in which the latest stored data is located.
[0023] Further, the target storage sector is determined from the plurality of storage sectors based on the storage sector in which the latest stored data is located, including:
[0024] If there is a free storage location in the storage sector in which the latest stored data is located, the storage sector in which the latest stored data is located is determined as the target storage sector from the plurality of storage sectors.
[0025] If there is no free storage location in the storage sector where the latest stored data is located, then the next adjacent storage sector corresponding to the storage sector where the latest stored data is located is determined from the plurality of storage sectors as the target storage sector.
[0026] Further, the state information of the stored data in the target storage sector after storing the to-be-stored data is updated, including:
[0027] After the to-be-stored data is stored in the target storage location in the target storage sector, the to-be-stored data is set as the latest stored data in the target storage sector, and the latest stored data is set as the state information representing the current state; and
[0028] The previous stored data adjacent to the latest stored data is updated from the state information representing the current state to the state information representing the valid state.
[0029] Further, after updating the state information of the stored data in the target storage sector after storing the to-be-stored data, the method further includes:
[0030] If the data query request is received, the exception information is obtained; wherein the exception information is recorded during the process of storing the to-be-stored data;
[0031] The stored data in the storage area is processed based on the exception information;
[0032] The target data corresponding to the data query request is queried in the stored data after the processing.
[0033] According to an aspect of an embodiment of the present application, a data storage device is provided, including:
[0034] The obtaining module is configured to obtain a target storage sector to which to-be-stored data is to be stored;
[0035] The determining module is configured to determine a target storage location of the to-be-stored data in the target storage sector based on the state information of the stored data in the target storage sector; wherein the state information is used to represent the state of the stored data;
[0036] The storage module is configured to store the to-be-stored data to the target storage location in the target storage sector;
[0037] The updating module is configured to update the state information of the stored data in the target storage sector after storing the to-be-stored data.
[0038] According to an aspect of the embodiments of the present application, an electronic device is provided, comprising: one or more processors; a storage device configured to store one or more programs, which, when executed by the one or more processors, cause the electronic device to implement the data storage method as described above.
[0039] According to an aspect of the embodiments of the present application, a computer readable storage medium is provided, which stores computer readable instructions. When the computer readable instructions are executed by a processor of a computer, the computer performs the data storage method as described above.
[0040] According to an aspect of the embodiments of the present application, a computer program product or computer program is provided, which comprises 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 the processor executes the computer instructions, so that the computer device performs the data storage method provided in the various optional embodiments described above.
[0041] In the technical solutions provided by the embodiments of the present application, when the to-be-stored data is generated, the target storage sector corresponding to the to-be-stored data is obtained, the target storage location of the to-be-stored data in the target storage sector is determined based on the state information of the stored data in the target storage sector, the to-be-stored data is stored in the corresponding target storage location, and the state information of the stored data is updated after the to-be-stored data is stored, so as to facilitate the storage of new to-be-stored data subsequently. According to the state information of the stored data, the corresponding storage location is determined, a storage medium for storing pointer information does not need to be separately arranged, the operation of writing data in another storage medium is reduced, the searching efficiency is improved, more frequent storage of to-be-stored data can be supported, and the complexity of storage is reduced.
[0042] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF DRAWINGS
[0043] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application. It is apparent that the accompanying drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor. In the drawings:
[0044] Figure 1 is a schematic diagram of an implementation environment related to the present application;
[0045] Figure 2is a flowchart of a data storage method to which the present application relates;
[0046] Figure 3 is a flowchart of step S210 in an embodiment to which the present application relates;
[0047] Figure 4 is a flowchart of step S320 in an embodiment to which the present application relates;
[0048] Figure 5 is a flowchart of step S420 in an embodiment to which the present application relates;
[0049] Figure 6 is a flowchart of step S430 in an embodiment to which the present application relates;
[0050] Figure 7 is a flowchart of step S240 in an embodiment to which the present application relates;
[0051] Figure 8 is a flowchart of another data storage method to which the present application relates;
[0052] Figure 9 is a flowchart of another data storage method to which the present application relates;
[0053] Figure 10 is a flowchart of step S910 in an embodiment to which the present application relates;
[0054] Figure 11 is a flowchart of step S910 in an embodiment to which the present application relates;
[0055] Figure 12 is a flowchart of step S920 in an embodiment to which the present application relates;
[0056] Figure 13 is a block diagram of a data storage apparatus to which the present application relates;
[0057] Figure 14 shows a structural schematic diagram of a computer system of an electronic device suitable for implementing an embodiment of the present application. DETAILED DESCRIPTION
[0058] The exemplary embodiments will now be described in detail with reference to the accompanying drawings. If described with reference to the accompanying drawings, the following description relates to the drawings, unless otherwise noted, the same reference numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all the implementations in accordance with this application. Rather, they are merely examples in accordance with some aspects of the present application as detailed in the appended claims.
[0059] The block diagrams shown in the drawings are merely functional entities, and do not necessarily correspond to physically independent entities. That is, the functional entities can be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0060] The flowcharts shown in the drawings are merely exemplary illustrations, and do not necessarily include all contents and operations / steps, nor are they necessarily executed in the order described. For example, some operations / steps can be further decomposed, and some operations / steps can be combined or partially combined, so the actual execution order can be changed according to actual conditions.
[0061] It should also be noted that "multiple" as mentioned in the present application refers to two or more. The association relationship of "and / or" describes the associated objects, which means that there can be three relationships, for example, A and / or B can represent the three cases of A alone, A and B together, and B alone. The character " / " generally represents an "or" relationship between the associated objects before and after it.
[0062] Please refer to Figure 1 , Figure 1 is a schematic diagram of an implementation environment involved in the present application. The implementation environment includes a power meter 110 and a server 120, which communicate through a wired or wireless network.
[0063] The server 120 stores the to-be-stored data generated by the power meter 110. As a data node in the power meter 110, the to-be-stored data is generated at every moment and saved in the server in the format of (time stamp + collected data). The server 120 can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, etc., which is not limited herein.
[0064] Figure 2 is a flowchart of a data storage method according to an exemplary embodiment. The method can be applied to Figure 1 the implementation environment shown in Figure 1 and specifically executed by the server 120 in the embodiment environment shown in Figure 2 In an exemplary embodiment, the data storage method can include steps S210 to S240, which are described in detail as follows:
[0065] Step S210, obtaining a target storage sector to which the to-be-stored data is to be stored.
[0066] In the embodiment of the present application, the to-be-stored data includes data generated by the smart meter, and the to-be-stored data includes corresponding time stamps and specific data. Each to-be-stored data is to be stored in a corresponding target storage sector. When the to-be-stored data is generated, the corresponding target storage sector is obtained.
[0067] In an exemplary embodiment of the present application, please refer to Figure 3 In step S210, obtaining a target storage sector to which the to-be-stored data is to be stored, includes steps S310 and S320, which are described in detail as follows:
[0068] Step S310, obtaining a storage area corresponding to the to-be-stored data, the storage area including a plurality of storage sectors.
[0069] In the embodiment of the present application, a storage area is set in advance, such as a data flash. The storage area is provided with a plurality of storage sectors. The plurality of storage sectors can include storage sectors that have been stored with data, storage sectors that have not stored any data, and storage sectors that have stored part of the data. When the to-be-stored data is generated, the corresponding storage area is obtained.
[0070] Step S320, determining a target storage sector from the plurality of storage sectors based on state information of the stored data in the plurality of storage sectors.
[0071] In the embodiment of the present application, when data is stored in the storage sector, the data is stored according to a first-in-first-out queue. The corresponding state information of the stored data is set. According to the state information of the stored data, it can be determined which storage sector the to-be-stored data is to be stored in, and the storage sector is taken as the target storage sector.
[0072] In an exemplary embodiment of the present application, please refer to Figure 4 In step S320, determining a target storage sector from the plurality of storage sectors based on state information of the stored data in the plurality of storage sectors, includes steps S410 to S430, which are described in detail as follows:
[0073] Step S410, for each storage sector, traversing the storage location in the storage sector based on the state information of the stored data in the storage sector.
[0074] In the embodiments of the present application, each storage sector is provided with a corresponding storage location, each storage location has corresponding state information, when the storage location stores data, the corresponding state information is the same as the state information of the corresponding stored data, and the state information of the storage location without storing data is uniformly empty state Empty (FF). Each storage sector is traversed, and the storage location in the storage sector is traversed based on the state information of the stored data.
[0075] In step S420, the storage sector in which the latest stored data is located is determined based on the traversal condition.
[0076] In the embodiments of the present application, when storing data, the state information corresponding to the latest stored data is different from the state information corresponding to the previously stored data, and the storage sector in which the stored data is located can be determined according to the traversal condition.
[0077] In an exemplary embodiment of the present application, please refer to Figure 5 In step S420, the storage sector in which the latest stored data is located is determined based on the traversal condition, including steps S510 to S540, which are described in detail as follows:
[0078] In step S510, if the state information of the last storage location in the traversed storage sector represents the empty state, the storage sector whose state information of the last storage location represents the empty state is taken as the candidate storage sector.
[0079] In the embodiments of the present application, when traversing the plurality of storage sectors, the last storage location of the storage sector is preferentially traversed, and if the state information of the last storage location represents the empty state, it can be determined that the storage sector does not store data or stores part of the data, and these storage sectors are taken as the candidate storage sector.
[0080] In step S520, it is detected whether the state information of the storage location in the candidate storage sector represents the current state.
[0081] In the embodiments of the present application, the state information of each storage location in the candidate storage sector is traversed, and whether the state information of at least one storage location is the current state.
[0082] In step S530, if the state information of the storage location represents the current state, the candidate storage sector is taken as the storage sector in which the latest stored data is located.
[0083] In the embodiments of the present application, if the storage location of the candidate storage sector in the candidate storage sector is the current state, the candidate storage sector is taken as the storage sector in which the latest stored data is located.
[0084] In another embodiment of the present application, there can be a device failure, which in turn causes the corresponding update to fail when updating the state information of the stored data, resulting in the state information of the plurality of storage locations being indicative of the current state. When it is detected that the state information of at least two storage locations is indicative of the current state, the timestamp corresponding to the stored data stored in the corresponding storage location is obtained, and the stored data with the largest timestamp is determined to be the latest stored data, i.e., the stored data closest to the current time is the latest stored data.
[0085] In step S540, if not, the last storage location of the traversed storage sector whose state information is indicative of the current state is taken as the storage sector in which the latest stored data is located.
[0086] In the embodiment of the present application, if there is no storage location of the candidate storage sector that is indicative of the current state, it indicates that the latest stored data is stored in the last storage location of a certain storage sector. Therefore, the last storage location of the traversed storage sector whose state information is indicative of the current state is taken as the storage sector in which the latest stored data is located.
[0087] In storing the to-be-stored data, a storage sector in which the state information of the first storage location and the last storage location is empty can be directly selected as the target storage sector, or each storage sector can be numbered in advance, and the next adjacent storage sector corresponding to the storage sector in which the latest stored data is located is determined as the target storage sector. Further, in storing the data, the data is stored in a first-in first-out queue, i.e., some data in the stored data can be deleted, thereby leaving some storage sectors empty. When numbering the storage sectors, the empty storage sectors need to be updated. For example, five storage sectors are pre-set, and the existing numbers of the five storage sectors are 1-5 in sequence. After data processing, the data in the first storage sector and the second storage sector is completely deleted, and part of the data in the third storage sector is deleted. Therefore, the numbers of the storage sectors are updated, the number of the third storage sector is set to 1, the number of the fourth storage sector is set to 2, the number of the fifth storage sector is set to 3, the number of the first storage sector is set to 4, and the number of the second storage sector is set to 5.
[0088] In step S430, the target storage sector is determined from the plurality of storage sectors based on the storage sector in which the latest stored data is located.
[0089] In the embodiment of the present application, the target storage sector is determined from the plurality of storage sectors based on the storage sector in which the latest stored data is located.
[0090] In an exemplary embodiment of the present application, please refer toFigure 6 In step S430, the target storage sector is determined from the plurality of storage sectors based on the storage sector in which the latest stored data is located, including steps S610 and S620, which are described in detail as follows:
[0091] In step S610, if there is a free storage location in the storage sector in which the latest stored data is located, the storage sector in which the latest stored data is located is determined as the target storage sector from the plurality of storage sectors.
[0092] In the embodiment of the present application, if there is a free storage location in the storage sector in which the latest stored data is located, i.e., there is a storage location with a null state information, the storage sector in which the latest stored data is located is determined as the target storage sector.
[0093] In step S620, if there is no free storage location in the storage sector in which the latest stored data is located, the next adjacent storage sector corresponding to the storage sector in which the latest stored data is located is determined as the target storage sector from the plurality of storage sectors.
[0094] In the embodiment of the present application, if there is no free storage location in the storage sector in which the latest stored data is located, i.e., there is no storage location with a null state information, the next adjacent storage sector corresponding to the storage sector in which the latest stored data is located is determined as the target storage sector.
[0095] In step S220, the target storage location of the to-be-stored data in the target storage sector is determined based on the state information of the stored data in the target storage sector; wherein the state information is used to represent the state of the stored data.
[0096] In the embodiment of the present application, the target storage location is determined according to the state information of the stored data in the target storage sector. Specifically, when the target storage sector stores the stored data, the target storage location is determined according to the state information of the stored data, i.e., the next adjacent storage location of the stored data representing the current state is taken as the target storage location. When the target storage sector does not store the stored data, the first storage location of the target storage sector is directly taken as the target storage location.
[0097] In step S230, the to-be-stored data is stored in the target storage location in the target storage sector.
[0098] In the embodiment of the present application, the to-be-stored data is stored in the target storage location of the target storage sector.
[0099] In step S240, the state information of the stored data in the target storage sector after storing the to-be-stored data is updated.
[0100] In the embodiment of the present application, after the to-be-stored data is stored in the target storage location of the target storage sector, the to-be-stored data can be regarded as stored data, and the state information of the stored data in the target storage sector after storing the to-be-stored data is updated, so as to facilitate storage of new to-be-stored data.
[0101] In the embodiment of the present application, when the to-be-stored data is generated, the target storage sector corresponding to the to-be-stored data is acquired, the target storage location of the to-be-stored data in the target storage sector is determined based on the state information of the stored data in the target storage sector, and after the to-be-stored data is stored in the corresponding target storage location, the state information of the stored data is updated, so as to facilitate storage of new to-be-stored data. The present application determines the corresponding storage location according to the state information of the stored data, does not need to separately set a storage medium for storing pointer information, reduces the operation of writing data in another storage medium, can support more frequent storage of to-be-stored data, and at the same time reduces the complexity of storage.
[0102] In an example embodiment of the present application, please refer to Figure 7 In step S240, the state information of the stored data in the target storage sector after storing the to-be-stored data is updated, including step S710 and step S720, which are described in detail as follows:
[0103] In step S710, after the to-be-stored data is stored in the target storage location in the target storage sector, the to-be-stored data is regarded as the latest stored data in the target storage sector, and the latest stored data is set as state information representing the current state; and
[0104] In the embodiment of the present application, after the to-be-stored data is stored in the target storage location, the to-be-stored data can be regarded as the latest stored data, and the latest stored data is set as state information representing the current state.
[0105] In step S720, the last stored data adjacent to the latest stored data is updated from state information representing the current state to state information representing the valid state.
[0106] In the embodiment of the present application, the state information of the last stored data adjacent to the latest stored data, i.e., the last latest stored data, is updated from the current state to the valid state Valid (66).
[0107] In an example embodiment of the present application, please refer to Figure 8 After the state information of the stored data in the target storage sector after storing the to-be-stored data is updated in step S240, the data storage method further includes step S810 to step S830, which are described in detail as follows:
[0108] Step S810: If a data query request is received, obtain the exception information; wherein, the exception information is recorded during the process of storing the data to be stored.
[0109] In this embodiment, after each piece of data to be stored is stored in the target storage location, its timestamp is compared with the timestamp of the corresponding adjacent previously stored data. If the timestamp of the data to be stored is less than the timestamp of the corresponding adjacent previously stored data, an anomaly is recorded. All recorded anomalies are summarized into an anomaly information, which includes the number of anomalies and the location where each anomaly occurred. When a data query request is received, the anomaly information is retrieved. This application detects the corresponding timestamp during the storage of data to be stored, which improves the reliability and stability of data storage to a certain extent.
[0110] Step S820: Based on the anomaly information, the stored data in the storage area is segmented.
[0111] In this embodiment of the application, the data is segmented according to the number of anomalies in the anomaly information and the location of each anomaly. That is, the data is segmented at the location corresponding to each anomaly to obtain multiple data segments.
[0112] Step S830: Query the target data corresponding to the data query request in the segmented stored data.
[0113] In this embodiment, all data is stored in a first-in-first-out queue. The timestamps of the data stored in the storage area are arranged in ascending order. Therefore, the timestamps of each data segment after segmentation are also arranged in ascending order. Thus, each data segment can be searched using a binary search method to find whether there is data within the query time range corresponding to the data query request. In this embodiment, the time complexity of finding the target data using the binary search method is O(log n) in the worst case, which is more efficient than traversal query, thus improving the meter reading efficiency to a certain extent.
[0114] like Figure 9 As shown in an exemplary embodiment, a flowchart of a data storage method is illustrated. This data storage method may include steps S910 to S960, which are described in detail below:
[0115] Step S910: Obtain the data to be stored, and determine the storage information of the data to be stored based on the status information of the stored data in the storage area.
[0116] In this embodiment of the application, after data to be stored is generated, the corresponding storage information is determined based on the status information of the data already stored in the storage area, and based on the storage information, it can be determined which storage location the data to be stored should be stored in.
[0117] Step S920, according to the storage information, the information to be stored is stored to the target storage location corresponding to the storage area, and the state information of the stored data in the target storage sector after storing the to-be-stored data is updated.
[0118] In the embodiment of the application, the to-be-stored information is stored to the target storage location according to the storage information, and the latest stored data is set as the state information representing the current state, and the state information of the adjacent previous stored data, i.e., the previous latest stored data, is updated to the valid state from the current state.
[0119] Step S930, the timestamp of the latest stored data is compared with the timestamp of the corresponding adjacent previous stored data.
[0120] In the embodiment of the application, when the to-be-stored data is stored to the corresponding target storage location, the to-be-stored data can be used as the latest stored data, and the timestamp of the latest stored data is compared with the timestamp of the corresponding adjacent previous stored data.
[0121] Step S940, if the timestamp of the latest stored data is less than the timestamp of the corresponding adjacent previous stored data, an abnormal event is generated, and all abnormal events are summarized to obtain abnormal information.
[0122] In the embodiment of the application, when the data is stored, the data is stored according to the first-in first-out queue. If the timestamp of the latest stored data is less than the timestamp of the corresponding adjacent previous stored data, it indicates that an exception occurs during storage, and this is recorded as an abnormal event. All abnormal events are summarized to obtain abnormal information.
[0123] Step S950, if a data query request is received, the stored data in the storage area is processed based on the abnormal information.
[0124] In the embodiment of the application, the above step S950 is consistent with the description of the foregoing step S820, and will not be repeated here.
[0125] Step S960, the target data corresponding to the data query request is queried in the stored data after the segmentation processing.
[0126] In the embodiment of the application, the above step S960 is consistent with the description of the foregoing step S830, and will not be repeated here.
[0127] In an exemplary embodiment of the application, please refer to Figure 10The storage information includes first storage information representing the tail pointer and second storage information representing the head pointer. In step S910, the storage information of the data to be stored is determined based on the state information of the stored data in the storage area, including steps S1010 to S1070, which are described in detail as follows.
[0128] In step S1010, the state information of the first storage location and the state information of the last storage location of the currently traversed storage sector are obtained.
[0129] In the embodiments of the present application, the first storage location and the last storage location of the currently traversed storage sector are obtained.
[0130] In step S1020, it is detected whether the state information of the first storage location or the state information of the last storage location of the currently traversed storage sector represents the current state.
[0131] In the embodiments of the present application, it is detected whether the state information of the first storage location represents the current state. If the state information of the first storage location does not represent the current state, it is detected whether the state information of the last storage location represents the current state.
[0132] In step S1030, if yes, the currently traversed storage sector is taken as a candidate storage sector.
[0133] In the embodiments of the present application, if the state information of the first storage location or the state information of the last storage location represents the current state, the currently traversed storage sector is taken as a candidate storage sector.
[0134] In step S1040, if no, it is detected whether the state information of the first storage location or the state information of the last storage location of the currently traversed storage sector represents the valid state or the empty state.
[0135] In the embodiments of the present application, if the state information of the first storage location or the state information of the last storage location does not represent the current state, it is detected whether the state information of the first storage location represents the valid state. If the state information of the first storage location does not represent the valid state, it is detected whether the state information of the last storage location represents the empty state.
[0136] In step S1030, if yes, the currently traversed storage sector is taken as a candidate storage sector.
[0137] In the embodiments of the present application, if the state information of the first storage location represents the valid state or the state information of the last storage location represents the empty state, the currently traversed storage sector is taken as a candidate storage sector.
[0138] Step S1050, detecting whether the current traversed storage sector is the last storage sector.
[0139] In the embodiments of the present application, during the traversal, the traversal is performed according to the order corresponding to the storage sectors, and whether the current traversed storage sector is the last storage sector is detected, i.e., whether the traversal is completed is detected.
[0140] Step S1060, if not, jumping to execute the step of acquiring the state information of the first storage location and the state information of the last storage location of the current traversed storage sector until the current traversed storage sector is not the last storage sector.
[0141] In the embodiments of the present application, if the current traversed storage sector is not the last storage sector, the next storage sector is traversed again until all the storage sectors are traversed.
[0142] Step S1070, if yes, determining the first storage information of the to-be-stored data according to the state information of the stored data in the candidate storage sector.
[0143] In the embodiments of the present application, if the current traversed storage sector is the last storage sector, the storage locations with the state information being the current state are traversed in all the candidate storage sectors. If there are multiple storage locations with the state information being the current state, the information of the storage location with the maximum timestamp is determined as the first storage information, and the to-be-stored data is stored in the next storage location adjacent to the storage location with the maximum timestamp.
[0144] In an exemplary embodiment of the present application, please refer to Figure 11 The storage information includes the first storage information representing the tail pointer and the second storage information representing the head pointer, and the storage information of the to-be-stored data is determined based on the state information of the stored data in the storage region in step S910, including steps S1110 to S1160, which are described in detail as follows:
[0145] Step S1110, acquiring the state information of the first storage location of the current traversed storage sector and the state information of the last storage location of the adjacent previous storage sector of the current traversed storage sector.
[0146] In the embodiments of the present application, each storage sector is traversed in sequence, and the state information of the first storage location of the current traversed storage sector and the state information of the last storage location of the adjacent previous storage sector of the current traversed storage sector are acquired.
[0147] Step S1120, detecting whether the state information of the first storage location of the current traversed storage sector represents the valid state or the state information of the last storage location of the adjacent previous storage sector of the current traversed storage sector represents the null state.
[0148] In the embodiment of the present application, if the state information of the first storage location of the current traversed storage sector does not represent the valid state, and the state information of the last storage location of the adjacent previous storage sector of the current traversed storage sector does not represent the null value state, the current traversed storage sector is traversed according to the order corresponding to the storage sectors, and it is detected whether the current traversed storage sector is the last storage sector, i.e., whether the traversal is completed.
[0149] In step S1130, if yes, the current traversed storage sector is taken as the candidate storage sector.
[0150] In the embodiment of the present application, if the state information of the first storage location of the current traversed storage sector represents the valid state or the state information of the last storage location of the adjacent previous storage sector of the current traversed storage sector represents the null value state, the current traversed storage sector is taken as the candidate storage sector.
[0151] In step S1140, if no, it is detected whether the current traversed storage sector is the last storage sector.
[0152] In the embodiment of the present application, if the state information of the first storage location of the current traversed storage sector does not represent the valid state, and the state information of the last storage location of the adjacent previous storage sector of the current traversed storage sector does not represent the null value state, the current traversed storage sector is traversed according to the order corresponding to the storage sectors, and it is detected whether the current traversed storage sector is the last storage sector, i.e., whether the traversal is completed.
[0153] In step S1150, if no, the step of acquiring the state information of the first storage location of the current traversed storage sector and the state information of the last storage location of the adjacent previous storage sector of the current traversed storage sector is executed, until the current traversed storage sector is the last storage sector.
[0154] In the embodiment of the present application, if the current traversed storage sector is not the last storage sector, the next storage sector is traversed again, until all the storage sectors are traversed.
[0155] In step S1160, if yes, the second storage information of the to-be-stored data is determined according to the state information of the stored data in the candidate storage sector.
[0156] In the embodiment of the present application, if the current traversed storage sector is the last storage sector, the state information of the first storage location storing data in all the candidate storage sectors is traversed, and the storage location whose state information is the valid state is determined. If there are multiple storage locations whose state information is the valid state, the information of the storage location with the minimum time stamp is determined as the second storage information.
[0157] In an exemplary embodiment of the present application, please refer to Figure 12In step S920, the to-be-stored data is stored in the target storage location corresponding to the storage area according to the storage information, and the state information of the stored data in the target storage sector after storing the to-be-stored data is updated, including steps S1210 to S1240, which are described in detail as follows:
[0158] In step S1210, whether there is a free storage location in the storage sector where the latest stored data is located is detected according to the storage information.
[0159] In the embodiment of the present application, whether there is a free storage location in the storage sector where the latest stored data is located is detected, that is, whether storage is performed across storage sectors.
[0160] In step S1220, if there is no free storage location, the next storage sector adjacent to the storage sector where the latest stored data is located is erased, and the to-be-stored data is stored in the first storage location of the erased storage sector.
[0161] In the embodiment of the present application, if there is no free storage location in the storage sector where the latest stored data is located, a storage sector needs to be provided again for storing the to-be-stored data.
[0162] In step S1230, if there is a free storage location, the to-be-stored data is stored in the next storage location adjacent to the storage location corresponding to the latest stored data.
[0163] In the embodiment of the present application, if there is a free storage location in the storage sector where the latest stored data is located, the to-be-stored data is directly stored in the next storage location adjacent to the storage location corresponding to the latest stored data.
[0164] In step S1240, the to-be-stored data is set as the latest stored data, the latest stored data is set as the state information representing the current state, and the previous stored data adjacent to the latest stored data is updated from the state information representing the current state to the state information representing the valid state.
[0165] In the embodiment of the present application, the to-be-stored data after storage is set as the latest stored data, the state information of the latest stored data is set as the state information representing the current state, and the previous stored data adjacent to the latest stored data is updated from the state information representing the current state to the state information representing the valid state.
[0166] In one exemplary embodiment of the present application, please refer to Figure 13 , Figure 13 A data storage device according to an exemplary embodiment is shown, which comprises:
[0167] The acquisition module 1310 is configured to acquire a target storage sector to which to-be-stored data is to be stored;
[0168] The determination module 1320 is configured to determine a target storage position of the to-be-stored data in the target storage sector based on state information of stored data in the target storage sector; the state information is used to represent a storage state of the stored data;
[0169] The storage module 1330 is configured to store the to-be-stored data to the target storage position in the target storage sector;
[0170] The update module 1340 is configured to update the state information of the stored data in the target storage sector after the to-be-stored data is stored.
[0171] In an example embodiment of the present application, the storage module 1330 comprises:
[0172] The acquisition sub-module is configured to acquire a storage area corresponding to the to-be-stored data, the storage area comprising a plurality of storage sectors;
[0173] The determination sub-module is configured to determine the target storage sector from the plurality of storage sectors based on state information of stored data in the plurality of storage sectors.
[0174] In an example embodiment of the present application, the determination sub-module comprises:
[0175] The traversal unit is configured to, for each storage sector, traverse a storage position in the storage sector based on state information of stored data in the storage sector;
[0176] The first determination unit is configured to determine a storage sector in which the latest stored data is located based on the traversal;
[0177] The second determination unit is configured to determine the target storage sector from the plurality of storage sectors based on the storage sector in which the latest stored data is located.
[0178] In an example embodiment of the present application, the first determination unit comprises:
[0179] The first sub-unit is configured to, if the state information of the last storage position in the traversed storage sector represents a null state, take the storage sector in which the state information of the last storage position represents the null state as a candidate storage sector;
[0180] The detection sub-unit is configured to detect whether the state information of the storage position in the candidate storage sector represents a current state;
[0181] The second subunit is configured to, if the state information of the storage location exists, take the storage sector representing the current state as the storage sector where the latest stored data is located.
[0182] The third subunit is configured to, if the state information of the storage location does not exist, take the storage sector representing the current state as the storage sector where the latest stored data is located.
[0183] In an example embodiment of the present application, the second determining unit comprises:
[0184] The first determining subunit is configured to, if there is a free storage location in the storage sector where the latest stored data is located, determine the storage sector where the latest stored data is located as the target storage sector from the plurality of storage sectors.
[0185] The second determining subunit is configured to, if there is no free storage location in the storage sector where the latest stored data is located, determine the next adjacent storage sector corresponding to the storage sector where the latest stored data is located as the target storage sector from the plurality of storage sectors.
[0186] In an example embodiment of the present application, the updating module 1340 comprises:
[0187] The setting sub-module is configured to, after the to-be-stored data is stored in the target storage location in the target storage sector, take the latest stored data in the target storage sector, and set the latest stored data as the state information representing the current state; and
[0188] The updating sub-module is configured to update the previous stored data adjacent to the latest stored data from the state information representing the current state to the state information representing the valid state.
[0189] In an example embodiment of the present application, the data storage device further comprises:
[0190] The abnormal information obtaining module is configured to, if the data query request is received, obtain abnormal information; wherein the abnormal information is obtained during the process of storing the to-be-stored data.
[0191] The segment processing module is configured to perform segment processing on the stored data in the storage area based on the abnormal information.
[0192] The query module is configured to query the target data corresponding to the data query request in the stored data after the segment processing.
[0193] It should be noted that the data storage apparatus provided in the above embodiments and the data storage method provided in the above embodiments belong to the same concept, wherein the specific manner in which various modules, sub-modules, units and sub-units perform operations has been described in detail in the method embodiments, which will not be described here.
[0194] Embodiments of the present application also provide an electronic device, comprising: one or more processors; a storage apparatus configured to store one or more programs, when the one or more programs are executed by the one or more processors, the electronic device implements the data storage method provided in each of the above embodiments.
[0195] Figure 14 A structural schematic diagram of a computer system of an electronic device suitable for implementing embodiments of the present application is shown.
[0196] It should be noted that, Figure 14 The computer system 1400 of the electronic device shown is only an example and should not impose any limitation on the functions and use range of embodiments of the present application.
[0197] As Figure 14 shown, the computer system 1400 includes a central processing unit (CPU) 1401, which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 1402 or programs loaded from a storage portion 1408 into a random access memory (RAM) 1403, such as performing the methods described in the above embodiments. In the RAM 1403, various programs and data required for system operation are also stored. The CPU 1401, the ROM 1402, and the RAM 1403 are connected to each other through a bus 1404. An input / output (I / O) interface 1405 is also connected to the bus 1404.
[0198] The following components are connected to the I / O interface 1405: an input portion 1406 including input devices such as a keyboard and mouse; an output portion 1407 including output devices such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and a speaker; a storage portion 1408 including a hard disk; and a communication portion 1409 including a network interface card such as a LAN (Local Area Network) card, a modem, and the like. The communication portion 1409 performs communication processing via a network such as the Internet. A drive 1410 is also connected to the I / O interface 1405 as necessary. A removable media 1411 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, and the like is attached to the drive 1410 as necessary, so that a computer program read therefrom is installed in the storage portion 1408 as necessary.
[0199] In particular, the processes described above with reference to the flowcharts can be implemented as a computer software program according to embodiments of the present application. For example, embodiments of the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing a computer program for executing the methods illustrated by the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via the communication portion 1409, and / or installed from the removable media 1411. When the computer program is executed by the Central Processing Unit (CPU) 1401, various functions defined in the system of the present application are executed.
[0200] It should be noted that the computer-readable medium in the embodiments of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination thereof. The computer-readable storage medium may, for example, be an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any combination thereof. More specific examples of the computer-readable storage medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this application, the computer-readable storage medium can be any tangible medium that contains or stores a program used by an instruction execution system, apparatus or device, and can be used or combined with the same. In this application, the computer-readable signal medium can include a data signal carried in a baseband or as a part of a carrier wave, which carries computer-readable computer programs. Such a propagated data signal can take various forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, which can send, transmit, propagate or transport a program for use by or in connection with an instruction execution system, apparatus or device. The computer programs contained in the computer-readable medium can be transmitted by any suitable medium, including but not limited to wireless, wired, or the like, or any suitable combination thereof.
[0201] The flowcharts and block diagrams in the drawings illustrate the possible implementation architectures, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In the flowcharts or block diagrams, each block can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in different order than that shown in the drawings. For example, two blocks represented in succession can actually be executed substantially in parallel, and sometimes in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams or flowcharts, and the combination of blocks in the block diagrams or flowcharts, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0202] The units described in the embodiments of the present application can be implemented in the form of software, or can be implemented in the form of hardware, and the described units can also be arranged in a processor. In some cases, the names of the units do not constitute a limitation on the units themselves.
[0203] Another aspect of the present application also provides a computer readable storage medium, which stores a computer program. The computer program is executed by a processor to implement the method described above. The computer readable storage medium can be included in the electronic device described in the above embodiments, or can exist separately and not be assembled into the electronic device.
[0204] Another aspect of the present application also provides a computer program product or a 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 the processor executes the computer instructions to make the computer device execute the method provided in each of the above embodiments.
[0205] The above is only a preferred exemplary embodiment of the present application, and is not intended to limit the implementation of the present application. Those skilled in the art can easily make corresponding modifications or variations according to the main concept and spirit of the present application, and the protection scope of the present application should be subject to the protection scope required by the claims.
Claims
1. A data storage method, characterized in that, include: Obtain the storage area corresponding to the data to be stored, wherein the storage area includes multiple storage sectors; For each storage sector, the storage locations in the storage sector are traversed based on the status information of the data already stored in the storage sector; If the state information of the last storage location in the traversed storage sector represents a null value, then the storage sector whose state information of the last storage location represents a null value is taken as a candidate storage sector. The status information indicating whether there is a storage location in the candidate storage sector represents the current state; If it exists, the candidate storage sector whose status information represents the current state of the storage location will be used as the storage sector where the latest stored data is located; if it does not exist, the storage sector whose status information represents the current state of the last storage location among the traversed storage sectors will be used as the storage sector where the latest stored data is located. The storage sector is determined from the plurality of storage sectors based on the storage sector where the latest stored data is located; Based on the status information of the data already stored in the target storage sector, the target storage location of the data to be stored in the target storage sector is determined, including: taking the next adjacent storage location of the stored data that represents the current state as the target storage location; if there is no stored data in the target storage sector, the first storage location of the target storage sector is directly taken as the target storage location; wherein, the status information is used to represent the status of the stored data. The data to be stored is stored in the target storage location within the target storage sector; Update the status information of the data already stored in the target storage sector after storing the data to be stored.
2. The method as described in claim 1, characterized in that, Determining the target storage sector from the plurality of storage sectors based on the storage sector where the latest stored data is located includes: If there is a free storage location in the storage sector where the latest stored data is located, then the storage sector where the latest stored data is located is determined from the plurality of storage sectors as the target storage sector; If there is no free storage location in the storage sector where the latest stored data is located, then the next adjacent storage sector corresponding to the storage sector where the latest stored data is located is determined from the plurality of storage sectors as the target storage sector.
3. The method according to any one of claims 1 to 2, characterized in that, The step of updating the status information of the data already stored in the target storage sector after storing the data to be stored includes: After the data to be stored is stored in the target storage location within the target storage sector, it becomes the latest stored data in the target storage sector, and this latest stored data is set as state information representing the current state; and The previous stored data adjacent to the latest stored data is updated from the state information representing the current state to the state information representing the valid state.
4. The method according to any one of claims 1 to 2, characterized in that, After updating the status information of the data already stored in the target storage sector after storing the data to be stored, the method further includes: If a data query request is received, an exception information is obtained; wherein, the exception information is recorded during the process of storing the data to be stored; Based on the aforementioned anomaly information, the stored data within the storage area is segmented. The target data corresponding to the data query request is retrieved from the segmented stored data.
5. A data storage device, characterized in that, include: The acquisition module is configured to acquire the storage area corresponding to the data to be stored, wherein the storage area includes multiple storage sectors; For each storage sector, the storage locations in the storage sector are traversed based on the status information of the data already stored in the storage sector; if the status information of the last storage location in the traversed storage sector indicates a null value, then the storage sector whose status information of the last storage location indicates a null value is selected as a candidate storage sector. The status information indicating whether there is a storage location in the candidate storage sector represents the current state; If it exists, the candidate storage sector whose status information represents the current state is taken as the storage sector where the latest stored data is located; if it does not exist, the storage sector whose status information represents the current state of the last storage location in the traversed storage sectors is taken as the storage sector where the latest stored data is located; based on the storage sector where the latest stored data is located, the target storage sector is determined from the plurality of storage sectors. The determination module is configured to determine the target storage location of the data to be stored in the target storage sector based on the status information of the data already stored in the target storage sector. This includes: taking the next adjacent storage location of the stored data that represents the current state as the target storage location; and taking the first storage location of the target storage sector as the target storage location if no stored data is stored in the target storage sector. The status information is used to represent the status of the stored data. The storage module is configured to store the data to be stored in the target storage location within the target storage sector; The update module is configured to update the status information of the data already stored in the target storage sector after storing the data to be stored.
6. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the electronic device to implement the data storage method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, It stores computer-readable instructions that, when executed by the computer's processor, cause the computer to perform the data storage method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Information storage method and device of electronic tag
CN102054192A
Data storage method and device, electronic product and computer readable storage medium
CN111767234A