A data storage method for power utilization information collection terminal
By combining a categorized circular cache with fixed-length index entries and a double-page mirrored ping-pong structure of mirrored metadata log pages, the problems of low storage space utilization and data consistency in the electricity information collection terminal are solved, achieving efficient data storage and recovery.
Patent Information
- Application Number
- CN202611427246.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-15
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2046-09-15
AI Technical Summary
The existing storage mechanism of electricity information collection terminals has problems such as low storage space utilization, high risk of write amplification, and difficulty in ensuring data consistency during sudden power outages.
The system employs a combination of a categorized circular buffer and a single curve data file for storage. Fixed-length index entries record information such as measurement point mapping codes, curve type identifiers, start-second timestamps, physical offsets, and payload byte lengths. Combined with the double-page mirrored ping-pong structure of the mirrored metadata log pages and reverse verification of index entries, it enables sequential append writing of data and data recovery after sudden power outages.
It improves storage space utilization, reduces write amplification risk, shortens data retrieval time, and ensures data consistency and power-on recovery efficiency.
Smart Images

Figure CN122925396B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of smart grid electricity consumption information collection and storage technology, and relates to a data storage method for an electricity consumption information collection terminal. Background Technology
[0002] Currently, using smart meters and electricity information collection terminals to monitor electricity load curves and power data at high frequency and over long periods has become a core approach for the refined management of smart grids. However, existing technologies still have limitations in dealing with the lifespan constraints of non-volatile memory erase / write, high-frequency writing of large-capacity time-series data, and safety protection against sudden power outages.
[0003] First, there is the Flash operation technology based on segmented mirroring and cache transfer. For example, Chinese invention patent CN109597580B discloses a Flash operation method suitable for storing load curves of smart meters. By establishing a storage area and a mirror area proportionally and establishing a cache area in RAM, when the load curve is stored cyclically or the time is modified forward, the data is transferred to the mirror block in batches and then the original storage block is erased. Its drawback is that this scheme is essentially a static backup mechanism that relies on physical redundancy space to offset the risk of erasure. Because the mirror area is divided into a fixed proportion, the physical storage space is occupied for a long time, resulting in low storage space utilization. At the same time, there are multiple frequent data transfers between the storage block, the cache area and the mirror block, which increases the frequency of physical read and write interactions of the underlying Flash. In the mid-to-late stage of high-frequency cyclic writing scenarios, it is easy to accelerate the physical media decay, and fails to solve the contradiction between storage overhead and device life.
[0004] Second, there is file storage technology based on globally shared data files and virtual positioning. For example, Chinese invention patent CN106095828B discloses a curve data storage scheme based on an electricity information collection terminal. It establishes multiple channel index files to share a single curve data file, and combines MAP header record conversion coefficients and file size virtual positioning technology to achieve backtracking and periodic pruning. Its drawbacks are: this technology focuses on logical decoupling and file operation frequency reduction. Although it optimizes the startup traversal efficiency, multiple index files are highly dependent on a single physical data file. When multiple measurement points are written concurrently or there is a sudden power outage, it is difficult to achieve synchronous atomic updates between the index header and the physical data area, which can easily lead to index offset and data deadlock. In addition, relying on the creation of temporary files and the overall renaming mechanism for data pruning still comes with a high risk of write amplification and additional overhead of the file system.
[0005] Third, data protection technology based on dual-region cyclic backup and comparison recovery; for example, Chinese invention patent CN106648982B discloses a method for storing power-off protection data of an electricity meter. It sets up cyclic backup storage areas A and B in a non-volatile memory, and works with RAM power-off protection data blocks and CRC verification. Write operations are initiated at regular intervals and during power failures, and data is restored according to the maximum power consumption when power is restored. Its shortcomings are: this technology is mainly aimed at the instantaneous snapshot protection of small-capacity key metering parameters. Its algorithm design strongly binds the data recovery logic to monotonically increasing scalar physical quantities, and lacks the ability to structure and model long-term, large-capacity, and non-monotonic multidimensional continuous load curve data; and it relies on full-disk traversal verification and dual-region comparison recovery, which will cause a surge in power-on initialization delay and system real-time response lag in large-capacity data storage scenarios.
[0006] Therefore, the technical problem to be solved by this invention is how to construct a data storage architecture with high space utilization, low write amplification risk, and the ability to recover from power loss of long-sequence continuous data, so that the storage management logic converges to a highly reliable physical security boundary with low hardware overhead. Summary of the Invention
[0007] The purpose of this invention is to overcome the shortcomings of the prior art and solve the technical problems of serious flash write amplification, storage fragmentation, long physical addressing time, and difficulty in ensuring data consistency during sudden power outages in the existing storage mechanism of electricity information collection terminals, and to provide a data storage method for electricity information collection terminals.
[0008] To achieve the above-mentioned objectives, the present invention provides a data storage method for an electricity consumption information collection terminal, comprising the following steps: Step S1: Parse the received data packet, extract the payload and push it into the classification buffer: Parse the received power curve data packet, extract the measurement point mapping code, curve type identifier and payload data, and push the payload data into the corresponding classification ring buffer according to the curve type identifier. Step S2, read the end-of-file write pointer when the write condition is met: When the data accumulation in the classification ring buffer reaches the sector write threshold or the channel buffer timer times out, read the end-of-file write pointer of the single curve data file recorded in the mirror metadata log page. Step S3: Construct a fixed-byte index entry based on the write pointer: Construct a fixed-byte index entry based on the write pointer at the end of the single curve data file. The index entry includes the measurement point mapping code, curve type identifier, start second-level timestamp, physical offset, payload byte length, transaction status flag, and checksum. Step S4, appending payload data to the data file and updating the tail write pointer: sequentially append the payload data to the tail write pointer position of the single curve data file, and update the tail write pointer of the single curve data file. Step S5, append index entries and commit transactions to the metadata log page: append index entries to the end of the corresponding curve index file, update the curve index file write pointer, and commit the incremented transaction sequence number and the updated write pointer to the mirror metadata log page; Step S6, Reverse verification of index rollback to valid data boundary in case of an anomaly: During power-on reset, verify the mirrored metadata log page, read the two mirrored pages stored in flash memory, and calculate the global CRC32 checksum of the two mirrored pages respectively; if both mirrored pages are verified correctly, compare the transaction sequence numbers recorded in the two mirrored pages, and establish the page with the larger transaction sequence number as the valid transaction base; if one page is verified incorrectly, establish the page with the correct verification as the valid transaction base; read the physical page data after the write pointer recorded in the valid transaction base of the single curve data file, and verify the hardware at the end of the physical page. Status word; when the hardware status word indicates that there is an unprogrammed all 0xFF physical bit field in the physical page, a data programming interruption is determined, and the write pointer of the single curve data file is reset to the position of the valid transaction baseline record; when an abnormal check or physical offset is detected at the end of the curve index file, the index entries are checked in reverse from the end of the curve index file, the qualified index entries that match the transaction sequence number and pass the check are located, the physical offset of the qualified index entries and the length of the payload bytes are extracted to calculate the valid data boundary, and the write pointers of the single curve data file and the curve index file are truncated and rolled back to the valid data boundary.
[0009] The index entries described in this invention occupy a fixed 16B of physical storage space in the flash memory medium. The structural members of the index entries are defined sequentially in a fixed physical order as follows: 2B measurement point mapping code, 1B curve type identifier, 4B start-second timestamp, 4B physical offset, 2B payload byte length, 1B transaction status flag, and 2B CRC16 checksum. When retrieving curve data for a specified measurement point, the physical addressing location of the target index entry is calculated directly by multiplying the fixed 16B length by the physical offset, based on the measurement point mapping code and the specified index number. Addressing with time complexity.
[0010] The mirrored metadata log page described in this invention is stored in flash memory using a double-page mirrored ping-pong structure. The mirrored page records the transaction sequence number, the write pointer to the end of the single curve data file, the write pointers to the end of each curve index file, and the global CRC32 checksum. In step S5, the process of submitting to the mirrored metadata log page includes: writing the incremented transaction sequence number, the updated write pointer to the end of the single curve data file, and the updated write pointer to the curve index file into the mirrored metadata log page in the standby state; calculating the CRC32 checksum of the mirrored metadata log page after writing and brushing it to the end of the page; and brushing the hardware control bit to switch the mirrored metadata log page in the standby state to the main working page.
[0011] In step S4 of the present invention, writing the payload data into a single curve data file includes the following sub-steps: Step S41, calculating the overlap boundary between the data segment and the flash physical page and physical sector in real time; Step S42, when the added payload data segment crosses the current flash physical sector boundary, the data segment is divided into a front segment data and a back segment data. The front segment data fills the current physical sector and is flushed to disk, and the back segment data is written to the starting position of the next new physical sector to eliminate the secondary rewriting caused by cross-sector misalignment.
[0012] In this invention, when the physical space occupied by the curve index file reaches a given storage threshold, a background low-priority index compression process is initiated for each curve index file; historical index entries in the curve index file are parsed according to the measurement point mapping code; historical index entries with the same measurement point mapping code are physically rearranged according to the timestamp; index entries with consecutive adjacent timestamps are merged into a range index block; the flash memory space occupied by the merged historical index entries is released; and the erase frequency of flash memory sectors is balanced.
[0013] In step S2 of the present invention, monitoring the data accumulation in the classification ring buffer includes: establishing an independent channel buffer for each curve type identifier; when the number of data bytes accumulated in any channel buffer reaches an integer multiple of the physical page size of the flash memory, or when the timer of the channel buffer exceeds a given waiting time threshold, triggering a data flush command for the corresponding channel buffer.
[0014] The curve type identifiers described in this invention include load curve identifiers, daily freeze curve identifiers, monthly freeze curve identifiers, and transient event curve identifiers. A separate curve index file is created for each type of curve identifier. All curve index files share a single curve data file stored in flash memory. Independent retrieval is achieved in their respective curve index files through the measurement point mapping code and the curve type identifier.
[0015] Compared with the prior art, the present invention has at least the following beneficial effects: 1. In the data storage of electricity information collection terminals, the use of classified ring buffers in conjunction with single curve data files enables the sequential appending of data generated by different measurement points and different curve types. Data can be retrieved and managed through curve index files corresponding to each curve type. This reduces the frequent updates of a large number of directory entries and index nodes in traditional file systems, reduces write amplification and storage fragmentation caused by continuous data writing, improves the utilization rate of continuous flash memory space, reduces wear and tear on flash memory media during storage, and helps extend the lifespan of storage media.
[0016] 2. Fixed-length index entries are used to record information such as measurement point mapping codes, curve type identifiers, start-second timestamps, physical offsets, and payload byte lengths. The storage location of the target index entry can be directly calculated based on the target index sequence number and the fixed index byte length. Compared with the step-by-step traversal of file trees or database index trees, this method makes the curve data location process more direct, reduces the uncertain time consumption caused by multi-level retrieval, shortens the data retrieval response time, and improves data addressing efficiency.
[0017] 3. By using the double-page mirrored ping-pong structure of the mirrored metadata log pages and the reverse verification of index entries, a valid transaction baseline can be determined after a sudden power outage and power-on at the terminal. The last complete and valid index entry is located backward from the end of the curve index file. Based on this, the write pointers of the single curve data file and the curve index file are rolled back to the valid position. This can clear data that was not completely written during the power outage, reduce logical pointer misalignment and data inconsistency problems, and eliminate the need for a global scan of the entire storage space, thereby improving power-on recovery efficiency and ensuring the consistency of stored data. Attached Figure Description
[0018] Figure 1 This is a schematic diagram of the data appending, storage, and reverse rollback process of the present invention; Figure 2 This is a schematic diagram of the storage and power failure repair state transition of the present invention. Detailed Implementation
[0019] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments and accompanying drawings.
[0020] Example 1: This embodiment discloses a data storage method for an electricity consumption information collection terminal, including the following steps: Step S1: Parse the received data packet, extract the payload and push it into the classification buffer: Parse the received power curve data packet, extract the measurement point mapping code, curve type identifier and payload data, and push the payload data into the corresponding classification ring buffer according to the curve type identifier. Step S2, read the end-of-file write pointer when the write condition is met: When the data accumulation in the classification ring buffer reaches the sector write threshold or the channel buffer timer times out, read the end-of-file write pointer of the single curve data file recorded in the mirror metadata log page. Step S3: Construct a fixed-byte index entry based on the write pointer: Construct a fixed-byte index entry based on the write pointer at the end of the single curve data file. The index entry includes the measurement point mapping code, curve type identifier, start second-level timestamp, physical offset, payload byte length, transaction status flag, and checksum. Step S4, appending payload data to the data file and updating the tail write pointer: sequentially append the payload data to the tail write pointer position of the single curve data file, and update the tail write pointer of the single curve data file. Step S5, append index entries and commit transactions to the metadata log page: append index entries to the end of the corresponding curve index file, update the curve index file write pointer, and commit the incremented transaction sequence number and the updated write pointer to the mirror metadata log page; Step S6, Reverse verification of index rollback to valid data boundary in case of an anomaly: During power-on reset, verify the mirrored metadata log page, read the two mirrored pages stored in flash memory, and calculate the global CRC32 checksum of the two mirrored pages respectively; if both mirrored pages are verified correctly, compare the transaction sequence numbers recorded in the two mirrored pages, and establish the page with the larger transaction sequence number as the valid transaction base; if one page is verified incorrectly, establish the page with the correct verification as the valid transaction base; read the physical page data after the write pointer recorded in the valid transaction base of the single curve data file, and verify the hardware at the end of the physical page. Status word; when the hardware status word indicates that there is an unprogrammed all 0xFF physical bit field in the physical page, a data programming interruption is determined, and the write pointer of the single curve data file is reset to the position of the valid transaction baseline record; when an abnormal check or physical offset is detected at the end of the curve index file, the index entries are checked in reverse from the end of the curve index file, the qualified index entries that match the transaction sequence number and pass the check are located, the physical offset of the qualified index entries and the length of the payload bytes are extracted to calculate the valid data boundary, and the write pointers of the single curve data file and the curve index file are truncated and rolled back to the valid data boundary.
[0021] In this embodiment, the physical storage space occupied by the index entry in the flash memory medium is fixed at 16 bytes. The structural members of the index entry are defined in a fixed physical order as follows: 2 bytes of measurement point mapping code, 1 byte of curve type identifier, 4 bytes of start-second timestamp, 4 bytes of physical offset, 2 bytes of payload byte length, 1 byte of transaction status flag, and 2 bytes of CRC16 checksum. When retrieving curve data for a specified measurement point, the physical addressing position of the target index entry is calculated directly by multiplying the fixed 16-byte length with the physical offset based on the measurement point mapping code and the specified index number. Addressing with time complexity.
[0022] The mirrored metadata log page described in this embodiment is stored in flash memory using a dual-page mirrored ping-pong structure. The mirrored page contains the transaction sequence number, the write pointer to the end of the single curve data file, the write pointers to the end of each curve index file, and the global CRC32 checksum. In step S5, the process of submitting to the mirrored metadata log page includes: writing the incremented transaction sequence number, the updated write pointer to the end of the single curve data file, and the updated write pointer to the curve index file into the mirrored metadata log page in the standby state; calculating the CRC32 checksum of the mirrored metadata log page after writing and brushing it to the end of the page; and brushing the hardware control bit to switch the mirrored metadata log page in the standby state to the main working page.
[0023] In step S4 of this embodiment, writing the payload data into a single curve data file includes the following sub-steps: Step S41, calculating the overlap boundary between the data segment and the flash physical page and physical sector in real time; Step S42, when the added payload data segment crosses the current flash physical sector boundary, the data segment is divided into a front segment data and a back segment data. The front segment data fills the current physical sector and is flushed to disk, and the back segment data is written to the starting position of the next new physical sector to eliminate the secondary rewriting caused by cross-sector misalignment.
[0024] In this embodiment, when the physical space occupied by the curve index file reaches a given storage threshold, a background low-priority index compression process is initiated for each curve index file. Historical index entries in the curve index file are parsed according to the measurement point mapping code. Historical index entries with the same measurement point mapping code are physically rearranged according to the timestamp. Index entries with consecutive adjacent timestamps are merged into range index blocks, releasing the flash memory space occupied by the merged historical index entries and balancing the erase frequency of flash memory sectors.
[0025] In step S2 of this embodiment, monitoring the data accumulation in the classification ring buffer includes: establishing an independent channel buffer for each curve type identifier; when the number of data bytes accumulated in any channel buffer reaches an integer multiple of the flash physical page size, or when the timer of the channel buffer exceeds a given waiting time threshold, triggering a data flush command for the corresponding channel buffer.
[0026] The curve type identifiers described in this embodiment include load curve identifiers, daily freeze curve identifiers, monthly freeze curve identifiers, and transient event curve identifiers. A separate curve index file is created for each type of curve identifier. All curve index files share a single curve data file stored in flash memory. Independent retrieval is achieved in their respective curve index files by using the measurement point mapping code and the curve type identifier.
[0027] Example 2: In this embodiment, under high-density industrial metering aggregation conditions, the electricity information acquisition terminal acts as an edge computing node, undertaking high-frequency acquisition tasks of multi-type electricity data from thousands of measurement points. The acquired data includes load curves, daily freeze curves, monthly freeze curves, and transient event curves. The system's internal microprocessor, combined with non-volatile flash memory, forms the main storage. However, due to the large granularity of flash memory erase blocks and the physical characteristic of minimum write operations being in page units, discrete file management methods experience write amplification effects and flash memory fragmentation due to frequent updates to index nodes and directory entries. Relational databases, with static memory usage exceeding the low-power terminal's capacity and lacking physical-level power-loss transaction protection, suffer write interruptions during sudden power outages, leading to logical pointer misalignment or checksum corruption. Building a data storage mechanism that balances fragmentation, deterministic physical addressing, and power-loss recovery in scenarios involving high-frequency appending and flushing of massive curve data presents significant technical challenges. To achieve deterministic physical addressing, the system establishes a mapping relationship between physical offsets and index addressing. Upon receiving a data query command, the storage controller obtains the logical sequence number of the target index entry to be queried. Based on the measurement point mapping code and the specified index sequence number, it calculates the physical addressing position of the target index entry according to the multiplication relationship between a fixed 16-byte length and the physical offset. Subsequently, it reads the 16-byte index entry at the physical addressing position, parses the 4-byte physical offset recorded therein, and uses this physical offset as a reference to perform physical addressing on a single curve data file, reading the corresponding payload data.
[0028] For multi-channel high-frequency concurrent write operations, the acquisition controller parses the received power curve data packets and pushes the payload data into the classification ring buffer corresponding to the curve type identifier. When the number of data bytes accumulated in the classification ring buffer reaches the flash physical sector write threshold of 4096B or the channel buffer timer times out, the storage controller reads the end-of-file write pointer of the single curve data file recorded in the mirror metadata log page. The 240B payload data in the classification ring buffer is appended to the physical offset 8162B of the single curve data file in the form of consecutive physical blocks, and the end pointer of the single curve data file is written. Updated to 8402B; simultaneously, the storage controller constructs index entries of fixed byte length 16B, whose structure members are 2B measurement point mapping codes in a fixed physical order. 0x000C, 1B Curve Type Identifier 0x01, 4B Starting second-level timestamp 0x66B79E00, 4B physical offset 8162B, 2B payload byte length 240B, 1B Transaction Status Flags 0x01 and 2BCRC16 checksum 0x8A3F, and append this index entry to the end of the corresponding load curve index file, setting the load curve index file write pointer. After updating from 320B to 336B and completing the data and index appending, the storage controller will increment the transaction sequence number. 1006. Write a pointer at the end of the updated single curve data file. 8402B and load curve index file write pointer The 336B writes to the standby image metadata log page, flushes the global CRC32 checksum, and switches the hardware control bits to complete the atomic transaction commit. The transaction sequence number and the two write pointers of the same commit jointly record the commit position corresponding to the transaction, and the valid transaction base is determined based on this when the power is reset.
[0029] A sudden power failure occurred when the payload data append was complete but only 8 bytes of index entries were written. After the terminal was powered on and reset, the power failure recovery module read two mirror pages of the mirror metadata log page. The backup mirror page had a global CRC32 checksum error because the write operation was incomplete. Therefore, the transaction sequence number recorded in the main working page was... 1005. Write a pointer to the end of a single curve data file. 8162B and load curve index file write pointer 320B was established as the valid transaction baseline. The detection module read the load curve index file and found that its actual physical length reached 328B, exceeding the write pointer of the curve index file recorded in the valid transaction baseline. Based on 320B, it is determined that there is a physical offset exceeding the limit at the end of the curve index file. The power-off recovery module reads the 8 bytes of incomplete data written from physical offset 320B to 328B and calculates the checksum. The CRC16 check fails, indicating that a power outage has occurred at this point. Subsequently, the index entries are checked in reverse from the end of the load curve index file to the beginning, using the transaction sequence number. 1005 corresponds to the curve index file write pointer 320B represents the end of the committed index for this transaction. The most recent complete index entry that passed CRC16 verification within this position is then used as the matching transaction sequence number. 1005 qualified index entries that have passed verification The qualified index entry The physical offset recorded in It is 7922B, with a payload byte length of [number missing]. It is 240B, according to the formula Calculate the effective data boundary ,get For 8162B, the storage controller truncates the write pointer at the end of the single curve data file and rolls it back to the valid data boundary 8162B. Based on the same valid transaction benchmark, it synchronously truncates and rolls back the write pointer of the load curve index file to 320B, clears the uncommitted data generated by the power failure, and updates the mirrored metadata log page to restore the logical structure consistency of the flash media.
[0030] During the power-on reset rollback process, the transaction sequence number... Qualified index entry corresponding to 1005 For index records that have been fully committed by the previous transaction, the actual physical offset is recorded internally. 7922B and payload byte length 240B, the power-down recovery module adds the physical offset 7922B to the payload byte length 240B to obtain the valid data boundary 8162B after the previous transaction commit. This value is consistent with the write pointer 8162B at the end of the single curve data file recorded in the main working page. Based on this, it is determined that the data before 8162B belongs to the committed historical data, and the write pointer at the end of the single curve data file is truncated and rolled back to 8162B to exclude the residual data appended at position 8162B by the incomplete transaction 1006.
[0031] Each curve index file shares the sequential append structure of a single curve data file, converging the physical storage of multi-source curve data into a unidirectional log append process within a single file structure. This avoids the write amplification effect and space fragmentation caused by frequent directory entries updates for discrete measurement points in traditional file systems, maintaining flash memory space utilization above 95%. A fixed 16-byte index entry is used for historical curve data retrieval. When retrieving curve data for a specified measurement point, the physical addressing location of the target index entry is calculated based on the measurement point mapping code and the specified index number, according to the multiplication relationship between the fixed 16-byte length and the physical offset. Deterministic physical addressing with time complexity; the mirrored metadata log pages of the double-page mirrored ping-pong structure and the reverse checkpoint rollback mechanism ensure that each append write has physical-level transaction atomic attributes. In the event of a sudden power failure and reset, the qualified index entry is located by checksum comparison and reverse check of the end index. Write pointer truncation and recovery are completed without the need for a full scan of the flash memory medium, ensuring the logical closed-loop consistency of storage data under long-term stable operation.
[0032] Example 3: This embodiment constructs a hardware test platform consisting of an embedded microprocessor with a main frequency of 120MHz and 256KB of random access memory and 64MB of SPI flash memory. This platform is used to verify the data storage method of the electricity information acquisition terminal under multi-point, high-frequency acquisition conditions. The flash memory physical sector size is 4096B, and the physical page size is 256B. The test platform is connected to an energy signal simulator to generate load curve data from 100 energy measurement points. The sampling interval is set to 15 minutes, and each data packet contains a 240B payload. A total of 288,000 raw data packets were collected over 30 days of continuous operation. Simultaneously, Gaussian white noise with a signal-to-noise ratio of 20dB is superimposed on the DC power supply bus, and a random power outage trigger circuit simulates sudden power outages and electromagnetic interference. A sector write threshold is used in the classified ring buffer. Controlling data flushing: The minimum physical erase unit for flash memory is 4096 bytes. When the sector write threshold is below 4096 bytes, data is prone to cross-sector misalignment writes and secondary read / write operations. Further increasing the threshold increases cache usage and the amount of data lost during power failure. Therefore, this embodiment sets the sector write threshold based on the physical sector boundary alignment. Set to 4096B and keep the total memory usage of the 4-channel classified ring cache below 16KB.
[0033] The test setup consisted of four independently running groups. The sample group of this invention employed a categorized circular cache, a single curve data file, index entries with a fixed byte length of 16 bytes, a mirrored metadata log page with a double-page mirrored ping-pong structure, and a reverse checkpoint repair mechanism. Control group 1 used a general discrete file system, establishing independent files and index nodes for each of the 100 measurement points. Control group 2 used a single data file sharing architecture and a variable-length index structure, reconstructing the index through a global linear scan upon power-on reset. Control group 3 used the same storage architecture as the sample group of this invention, only writing sectors to the threshold. Set to 512B, during 30 consecutive days of operation, the actual total amount of flash memory written, flash memory space utilization, and average historical data retrieval latency of each group were recorded. 500 random power-down injections were performed on each group, and the power-on repair success rate, average power-on repair latency, and number of corrupted historical valid data entries were recorded.
[0034] Based on 288,000 raw data packets and a 240B payload per packet, the total raw payload processed in each group was 69.12MB. Under the same raw payload, the actual total flash memory write volume of the sample group of this invention was 73.85MB, with a write amplification factor of 1.07; the actual total flash memory write volume of control group 1 was 284.77MB, corresponding to a write amplification factor of 4.12; the actual total flash memory write volume of control group 2 was 75.32MB, corresponding to a write amplification factor of 1.09; and the actual total flash memory write volume of control group 3 was 162.43MB, corresponding to a write amplification factor of 1.09. With a coefficient of 2.35, control group 1 needs to update the directory entries and index nodes of each independent file during the continuous writing process of 100 measurement points, and its actual writing volume increases accordingly. The sample group of the present invention appends the load curve data of each measurement point sequentially to a single curve data file and records the data position with an index entry with a fixed byte length of 16B, which reduces additional writing under the same original load. Corresponding to the above writing results, the flash memory space utilization rates of the sample group of the present invention, control group 1, control group 2 and control group 3 are 96.4%, 58.4%, 92.1% and 81.2%, respectively.
[0035] During the historical data retrieval process, control group 1 located the data step by step through the file tree, while control group 2 also needed to parse the variable-length index. The average historical data retrieval latency for the two groups was 48.6ms and 32.4ms, respectively. The sample group of this invention uses the measurement point mapping code and the specified index sequence number. The target index entry was determined, and its physical addressing location was calculated using a fixed 16-byte length multiplied by the physical offset. The payload data in the single curve data file was then located using the physical offset within the index entry. The average latency for historical data retrieval was 1.2ms. Control group 3, which used the same fixed-length index structure but set the sector write threshold to 512 bytes, had an average historical data retrieval latency of 1.8ms. Further gradient testing was conducted on the sector write threshold. The write amplification factor was increased from 512B to 4096B, and decreased from 2.35 to 1.07; [further details omitted]. After increasing to 8192B, the write amplification factor is 1.05, but the memory space occupied by the classified ring buffer also increases, and the risk of data loss due to power failure also increases accordingly. Therefore, this embodiment uses a sector write threshold of 4096B for subsequent testing.
[0036] During the random power-down injection process, control group 1 and control group 2 used the original file recovery method and the global linear scan method, respectively, to handle abnormal data after power-on reset. After 500 power-down injections, the power-on repair success rate of control group 1 was 81.2%, with an average power-on repair latency of 1840.5ms and 142 pieces of historical valid data corrupted; the power-on repair success rate of control group 2 was 89.4%, with an average power-on repair latency of 1240.2ms and 38 pieces of historical valid data corrupted. After adopting the mirrored metadata log page and reverse checkpoint repair mechanism, the power-on repair success rate of the sample group of this invention was 99.8%, with an average power-on repair latency of 18.4ms and 0 pieces of historical valid data corrupted; control group 3, which used the same storage architecture and a sector write threshold of 512B, had a power-on repair success rate of 98.2%, an average power-on repair latency of 24.6ms, and also 0 pieces of historical valid data corrupted.
[0037] When the prototype of this invention is powered on and reset, it uses a global CRC32 checksum and an incrementing transaction sequence number in the mirrored metadata log page with a two-page mirrored ping-pong structure. A valid transaction baseline is determined, and the write pointer of the curve index file corresponding to this valid transaction baseline is used as the boundary of the committed index. When a power failure causes half-page writes or CRC16 checksum errors to occur in the index entries, the boundary is determined. In the event of damage, the power-loss recovery module performs reverse verification from the end of the curve index file to the beginning, locating the qualified index entries that have passed the verification within the committed range corresponding to the valid transaction baseline. Extract the physical offset. With payload byte length ,according to Calculate valid data boundaries Then, the end-of-file write pointer of the single curve data file is truncated and rolled back to... The curve index file write pointer is synchronously reset based on the same valid transaction benchmark. The sequential append structure of multiple curve index files sharing a single curve data file, combined with the above reverse verification and truncation rollback process, enables the flash memory write volume, data retrieval latency and power failure recovery data in the test to be recorded and verified according to the same storage link.
[0038] Example 4: In this embodiment, during the non-uniform sampling and low-frequency power data acquisition process, the received data frames in the power consumption information acquisition terminal exhibit uneven temporal distribution. Consequently, the amount of data in the classified circular buffer is unlikely to reach the sector write threshold within a short period. 4096B, to reduce data loss due to sudden power outages when cached data has not been flushed to disk for extended periods, employs a channel cache timer to limit data waiting time thresholds. The calibration is based on the ratio of the flash memory physical page size (256 bytes) to the low-frequency sampling rate; when the data accumulation in any category of the circular buffer reaches... 4096B, or the channel buffer timer reaches... At 300 seconds, the storage controller retrieves the data segment from the cache and reads the end-of-file write pointer of the single curve data file recorded in the image metadata log page. 8162B, and the physical offset of the data packet to be submitted in the single curve data file. The value was determined to be 8162B. Subsequently, an index entry with a fixed byte length of 16B was constructed, whose members sequentially contained 2B measurement point mapping codes. 0x000C, 1B Curve Type Identifier 0x01, 4B Starting second-level timestamp 0x66B79E00, 4B physical offset 8162B, 2B payload byte length 240B, 1B Transaction Status Flags 0x01 and 2BCRC16 checksum 0x8A3F; After sequentially appending the 240B payload data to the physical offset 8162B of the single curve data file, write the pointer to the end of the single curve data file. In the updated 8402B, during the engineering calibration of the wait time threshold, the flash physical page size of 256B is divided by the payload size of a single data packet of 240B, and the result is rounded to obtain the cumulative number of data packets required to fill a minimum physical page, which is 1. This number of data packets is then mapped to the single time interval of low-frequency sampling. When the low-frequency sampling rate generates 1 data packet every 300s, the wait time threshold is 300s, ensuring that cached data enters the flash disk flushing process once every 300s at most, and reducing the impact of frequent writing of small fragments on flash memory lifespan.
[0039] To address the storage pressure caused by the continuous growth in the size of curve index files during 10 years of continuous terminal operation, the storage controller initiates a low-priority index compression process in the background, and a background thread monitors the space occupied by each curve index file and the storage threshold. The relationship is 1MB; when the curve index file occupies space... When the memory reaches 1MB, a background thread parses the historical index entries and extracts the measurement point mapping codes. According to the measurement point mapping code and starting second-level timestamp The historical index entries are physically rearranged, merging multiple index entries with the same measurement point mapping code and consecutive timestamps into a range index block. The range index block occupies 20 bytes of physical space, and its structure contains 2 bytes of measurement point mapping code. 1B curve type identifier 4B start second-level timestamp, 4B end second-level timestamp, 4B physical offset The merging process involves: 3B cumulative payload length and 2B CRC16 checksum; after merging, releasing the flash memory space occupied by the merged 16B historical index entries, and moving the retained valid entries to the front of the physical sector to distribute the frequency of flash sector erases, while retaining entries based on fixed-length indexes. In terms of time complexity, physical addressing involves a background thread performing index compression. It divides the index data in a curve index file into two physically independent segments: a merged segment and an unmerged segment. The merged segment, located at the beginning of the file, stores consecutive 20-byte range index blocks in physical order. The unmerged segment, located at the end of the file, continues to store consecutive 16-byte uncompressed index entries in append order. The mirrored metadata log page also records the merged segment boundary pointer. During physical addressing, the corresponding search object is first determined based on the measurement point mapping code, and the target timestamp is compared with the merged segment boundary. If the target time period belongs to a historical merged interval, the target range index number is multiplied by the fixed 20-byte length to locate the target range index block in the merged segment. If the target time period belongs to an unmerged interval, the target index number is subtracted from the number of merged entries, and then multiplied by the fixed 16-byte length to locate the target index entry in the unmerged segment. This ensures that physical addressing is completed with each index type having its fixed length even when both types coexist.
[0040] During the metadata update phase, the storage controller builds an array containing incrementing transaction sequence numbers. 1006. Write a pointer at the end of the updated single curve data file. 8402B and the updated curve index file write pointer A new metadata log frame (336B) is created and written to the standby mirror metadata log page. After writing the global CRC32 checksum to the end of the page, the valid flag in the hardware control bits of the primary working page is cleared, and the valid flag of the standby page is set, completing the mirror primary / standby state switch. If a sudden power failure occurs during the hardware control bit writing process, and the terminal detects a mismatch in the global CRC32 checksum of the standby mirror page upon power-on reset, the transaction sequence number recorded in the primary working page is retained. 1005. Write a pointer to the end of a single curve data file. 8162B and load curve index file write pointer Using 320B as the effective transaction baseline, when there is incompletely written corrupted data at the end of the load curve index file, the physical offset corresponding to this uncommitted record is 8162B, and the payload byte length is 0B; the power failure recovery module uses the load curve index file write pointer in the effective transaction baseline. 320B as a transaction sequence number 1005. The index entries are verified in reverse order from the end of the committed index range to the beginning. The most recent complete index entry that passed CRC16 verification within this committed range is located and used as the entry for the transaction sequence number. 1005 corresponds to and passes the verification of qualified index entries. The qualified index entry The physical offset recorded in It is 7922B, with a payload byte length of [number missing]. It is 240B, according to the formula The effective data boundary is calculated. The write pointer to the single curve data file is truncated to 8162B; then the write pointer to the end of the single curve data file is truncated and rolled back to the valid data boundary 8162B, and the write pointer to the load curve index file is truncated and rolled back to 320B based on the same valid transaction baseline, erasing uncommitted data and restoring data structure consistency.
[0041] Example 5: This embodiment combines Figures 1 to 2 This paper describes a data storage method for an electricity consumption information collection terminal, such as... Figure 1 As shown, the received data packet is parsed to extract the payload, and pushed into the classification buffer to execute step S1. When the write condition is met, the end-of-data-file write pointer is read to execute step S2. Based on the write pointer, a fixed-byte-length index entry is constructed to execute step S3. The payload data is appended to the data file and the end-of-data-file write pointer is updated to execute step S4. The index entry is appended and the transaction is committed to the metadata log page to execute step S5. When an anomaly is detected, the index is reverse-checked and rolled back to the valid data boundary to execute step S6.
[0042] like Figure 2 As shown, when the system performs a power-on reset and all verifications are correct, it enters the classification ring buffer, parses the received power curve data packets, and continuously pushes them into the classification ring buffer. When the sector write threshold is reached or the channel buffer timer times out, the data flows from the classification ring buffer to the append write to the single curve data file. During the append write to the single curve data file, it is committed to the mirror metadata log page, then switches to the main working page, and returns to the classification ring buffer by flushing the hardware control bits. If a sudden power failure occurs during the append write to the single curve data file, the system will experience a data programming interruption and perform a power-on reset again after the terminal is powered on. When an abnormal check or physical offset is detected at the end of the curve index file during the power-on reset, the system switches to performing reverse check of the index entries, calculates the valid data boundary by locating qualified entries, and then performs truncation and rollback to the valid data boundary to restore the logical structure consistency of the flash memory medium and reset to the classification ring buffer.
[0043] Example 6: In this embodiment, during terminal power-on initialization, the mirror metadata log page at the beginning of the flash memory medium is read, the global CRC32 checksums of the main working page and the spare page are verified respectively, and the transaction sequence numbers recorded in the two mirror pages are compared. When both mirror pages are verified correctly, and the transaction sequence number... When the transaction sequence numbers are 1005 and 1004 respectively, the main working page with the larger transaction sequence number is established as the valid transaction base, and the storage controller reads the end-of-file write pointer of the single curve data recorded on that page. 8162B and Load Curve Index File Write Pointer 320B reads the physical page data after the write pointer of the valid transaction baseline record in the single curve data file, verifies the hardware status word at the end of the physical page, and determines that a data programming interrupt has occurred when the hardware status word indicates that there is an unprogrammed all 0xFF physical bit field in the physical page, and resets the write pointer at the end of the single curve data file. Reset to position 8162B of the valid transaction baseline record.
[0044] When wear and tear indicators are detected in subsequent physical sectors, the storage controller adjusts the data write offset, substituting it into the physical offset calculation formula. Get the current write pointer 8162B, flash memory physical sector size The value is 4096B, calculated as follows: When the 240B payload data accumulated in the classified ring buffer is written to the flash memory, the storage controller appends the data sequentially to the 12258B physical offset position and appends a fixed-byte index entry of 16B to the end of the corresponding load curve index file, so that the physical offset skips the damaged sector and maintains the logical structure correspondence.
[0045] During physical sector alignment control, when the storage controller detects a bad block and performs offset adjustment, it rounds up the current write position according to the sector boundary. If the current write pointer is 8162B, it divides it by the sector size of 4096B and rounds up to obtain the next alignment boundary physical offset of 8192B for the current sector. If the physical sector corresponding to this alignment boundary is marked as damaged, the entire 4096B damaged sector is skipped and added to the alignment boundary to obtain the adjusted new data write physical offset of 12288B. 12288B is an integer multiple of 3 times 4096B. The new data is written starting from the first byte of the new physical sector.
[0046] To address the sector wear caused by long-cycle, high-frequency writes in flash memory, the storage controller monitors the cumulative number of disk flushes for each sector. Maximum number of erases per sector Substitute into the wear formula Get the cumulative number of disk refreshes. 10,000 erases, maximum number of erases per sector Calculated 100,000 times. When the wear level of a certain sector When the preset erase threshold of 0.80 is reached, the background thread migrates the data segment stored in that sector to a free physical sector and recalculates the valid data boundary; substituting into the formula... Take the physical offset 8162B, payload byte length It is 240B, calculated as follows After the data migration is complete, the storage controller updates the 4B physical offset of the corresponding entry in the load curve index file. Recalculate the CRC16 checksum of the 14-byte index data segment and refresh the tail 2-byte checksum field. Even after the physical location of the data changes, the process is still completed by multiplying a fixed-byte index entry with a fixed offset. Physical addressing with time complexity.
[0047] Both the storage threshold and the erase threshold were calibrated through engineering experiments. For a storage threshold of 1MB, the maximum random access memory allocated to the index cache by the terminal is 64KB. When the curve index file of a single curve reaches 1MB, equivalent to 65,536 indexes, the memory required for sorting is 32KB, which does not exceed the safe memory level. When the storage threshold is below 0.5MB, the background index compression process is frequently started, increasing the CPU load. When it is above 2MB, the required memory exceeds the predetermined capacity. For the preset erase threshold of 0.80, in the test, after the flash sector reaches 80% of the maximum number of erases, i.e., 80,000 times, the bit flip error rate begins to increase exponentially. Therefore, 0.80 is used as the boundary to trigger data migration. When the threshold is above 0.80, the risk of data corruption increases, and when it is below 0.60, the number of data migrations increases.
[0048] Example 7: In this embodiment, after the electricity information acquisition terminal receives the high-frequency power quality event curve data packet generated during a transient fault in the power grid, the acquisition controller parses the measurement point mapping code. 0x000C, Curve Type Identifier 0x04, Starting Second-Level Timestamp 0x66B79E00 and payload byte length 240B, and pushes the payload data into the classification ring buffer divided by curve type; the buffer management unit monitors the number of bytes occupied in the classification ring buffer in real time. When transient data concurrency causes Reaching the warning disk refresh threshold Emergency disk flushing is triggered at any time, among which Based on the total capacity of the classification ring buffer The product of 40960B and the safety factor of 0.80 is used to determine the formula. ,get For 32768B, when When the value reaches 32768B, the storage controller reads the end-of-file write pointer of the single curve data file recorded in the mirror metadata log page. 8162B, the current physical offset The value is determined to be 8162B, and an index entry with a fixed byte length of 16B is constructed; its structure members are, in sequence, 2B measurement point mapping codes. 0x000C, 1B Curve Type Identifier 0x04, 4B Starting second-level timestamp 0x66B79E00, 4B physical offset 8162B, 2B payload byte length 240B, 1B Transaction Status Flags 0x01 and 2BCRC16 checksum 0x8A3F, then prepare to append data to the flash memory to prevent memory overflow in the categorized circular buffer.
[0049] After appending 240B of payload data to the single curve data file at physical offset 8162B, the storage controller reads the flash memory hardware status register. When a power grid fault accompanied by power supply voltage fluctuations causes a flash memory programming write error, When a non-zero status value of 0x01 is returned, the storage controller starts the retry counter. If the write operation fails after three retries (the maximum retry limit), the current physical sector is marked as unavailable, and then... Calculate the adjusted physical offset; retrieve the current write pointer. 8162B, flash memory physical sector size The value is 4096B. Substitute it into the formula. ,get For 12258B, the storage controller re-appends 240B of payload data to the physical offset 12258B, and then... Calculate the updated data tail pointer; retrieve For 12258B, Substitute 240B into the formula. ,get The value is 12498B. Subsequently, the storage controller will use the physical offset from the transient event curve index entry. Corrected to 12258B, the CRC16 checksum of the 14B index field was recalculated, and... Updated to 0x9B21; the modified index entry with a fixed byte length of 16B is appended to the end of the transient event curve index file, and then... Calculate the updated index tail write pointer and retrieve the current curve index file write pointer. Substitute 320B into the formula. ,get For 336B, finally, the storage controller increments the transaction sequence number. 1007. Updated data tail pointer 12498B and the index tail write pointer 336B writes to the backup image metadata log page, calculates the global CRC32 checksum, and switches the hardware control bits to complete the atomic transaction commit, ensuring that the flash storage link maintains physical reproducibility and data structure consistency under abnormal hardware conditions.
Claims
1. A method for storing electricity information in a data collection terminal, characterized in that, Includes the following steps: Step S1: Parse the received power curve data packet, extract the measurement point mapping code, curve type identifier and payload data, and push the payload data into the corresponding classification ring buffer according to the curve type identifier. Step S2: When the data accumulation in the classification ring buffer reaches the sector write threshold or the channel cache timer times out, read the end-of-file write pointer of the single curve data file recorded in the mirror metadata log page. Step S3: Based on the write pointer at the end of the single curve data file, construct an index entry of fixed byte length. The index entry includes the measurement point mapping code, curve type identifier, start second-level timestamp, physical offset, effective payload byte length, transaction status flag, and check code. Step S4: Append the payload data sequentially to the end of the single curve data file and update the end of the single curve data file. Step S5: Append the index entries to the end of the corresponding curve index file, update the curve index file write pointer, and commit the incremented transaction sequence number and the updated write pointer to the mirror metadata log page. Step S6: During power-on reset, verify the mirror metadata log page, read the two mirror pages stored in flash memory, and calculate the global CRC32 checksum of the two mirror pages respectively; if both mirror pages are verified correctly, compare the transaction sequence numbers recorded in the two mirror pages, and establish the page with the larger transaction sequence number as the valid transaction base; if one page is verified incorrectly, establish the page with the correct verification as the valid transaction base. Read the physical page data of the single curve data file after the write pointer of the valid transaction baseline record, and verify the hardware status word at the end of the physical page; When the hardware status word indicates that there is an unprogrammed all 0xFF physical bit field in the physical page, a data programming interruption is determined to have occurred, and the write pointer of the single curve data file is reset to the position of the valid transaction baseline record; when an end-checking anomaly or physical offset exceeding the limit is detected in the curve index file, the index entries are checked in reverse from the end of the curve index file to locate the qualified index entries that match the transaction sequence number and pass the check, the physical offset of the qualified index entries and the payload byte length are extracted to calculate the valid data boundary, and the write pointers of the single curve data file and the curve index file are truncated and rolled back to the valid data boundary.
2. The data storage method for an electricity consumption information collection terminal according to claim 1, characterized in that, The physical storage space occupied by an index entry in the flash memory medium is fixed at 16 bytes. The structural members of the index entry are defined in a fixed physical order as follows: 2 bytes for the measurement point mapping code, 1 byte for the curve type identifier, 4 bytes for the start time stamp (second level), 4 bytes for the physical offset, 2 bytes for the payload byte length, 1 byte for the transaction status flag, and 2 bytes for the CRC16 checksum. When retrieving curve data for a specified measurement point, the physical addressing location of the target index entry is calculated directly by multiplying the fixed 16-byte length by the physical offset, based on the measurement point mapping code and the specified index number. Addressing with time complexity.
3. The data storage method for an electricity consumption information collection terminal according to claim 1, characterized in that, The mirrored metadata log page is stored in flash memory using a double-page mirrored ping-pong structure. The mirrored page contains the transaction sequence number, the write pointer to the end of the single curve data file, the write pointer to the end of each curve index file, and the global CRC32 checksum. In step S5, the process of submitting to the mirror metadata log page includes: writing the incremented transaction sequence number, the updated single curve data file end write pointer, and the updated curve index file write pointer to the mirror metadata log page in standby state; calculating the CRC32 checksum of the mirror metadata log page after writing and brushing it to the end of the page; and brushing the hardware control bits to switch the mirror metadata log page in standby state to the main working page.
4. The data storage method for an electricity consumption information collection terminal according to claim 1, characterized in that, In step S4, writing the payload data into a single curve data file includes the following sub-steps: Step S41, calculating the overlap boundaries of the data segment with the flash physical page and physical sector in real time; Step S42, when the added payload data segment crosses the current flash physical sector boundary, the data segment is divided into a front segment data and a back segment data. The front segment data fills the current physical sector and is flushed to disk, and the back segment data is written to the starting position of the next new physical sector to eliminate the secondary rewriting caused by cross-sector misalignment.
5. The data storage method for an electricity information collection terminal according to claim 1, characterized in that, For each curve index file, when the physical space occupied by the curve index file reaches the given storage threshold, a background low-priority index compression process is initiated. The historical index entries in the curve index file are parsed according to the measurement point mapping code. The historical index entries with the same measurement point mapping code are physically rearranged according to the timestamp. The index entries with consecutive adjacent timestamps are merged into a range index block, releasing the flash memory space occupied by the merged historical index entries and balancing the erase frequency of flash memory sectors.
6. The data storage method for an electricity information collection terminal according to claim 1, characterized in that, In step S2, monitoring the data accumulation in the classification ring buffer includes: establishing an independent channel buffer for each curve type identifier; when the number of data bytes accumulated in any channel buffer reaches an integer multiple of the flash physical page size, or when the timer of the channel buffer exceeds a given waiting time threshold, triggering a data flush command for the corresponding channel buffer.
7. The data storage method for an electricity consumption information collection terminal according to claim 1, characterized in that, Curve type identifiers include load curve identifiers, daily freeze curve identifiers, monthly freeze curve identifiers, and transient event curve identifiers. A separate curve index file is created for each type of curve identifier. All curve index files share a single curve data file stored in flash memory. Independent retrieval is achieved in their respective curve index files by using the measurement point mapping code and the curve type identifier.
Citation Information
Patent Citations
A curve data storage scheme based on an electricity consumption information collection terminal
CN106095828B
A method for storing power failure protection data in an electricity meter
CN106648982B
Flash operation method for storing load curves in smart meters
CN109597580B
Curve data storage scheme based on electric energy data acquire terminal
CN106095828A
Multi-level caching method and system for mass measuring points, medium and computer device
CN122293741A
