Log management method, device and terminal
By using log modification records in non-volatile memory to manage logs, the problem of low log management efficiency in the prior art is solved, and the write and read positions can be quickly located, improving operational efficiency and flexibility.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-30
- Publication Date
- 2026-03-31
AI Technical Summary
In existing technologies, the log management method of flash memory is inefficient, requiring traversal of the entire log storage space to determine the operation location, resulting in inflexible write and read operations.
Logs in non-volatile memory are managed using log modification records. Write and read addresses are calculated by finding the latest log modification record, avoiding traversing the entire storage space.
It improves the efficiency of writing and reading logs in non-volatile memory, enhances operational flexibility, and ensures the accuracy of writing and reading.
Smart Images

Figure CN115145887B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of memory technology, and in particular to a log management method, apparatus, and terminal. Background Technology
[0002] With the rapid development of IoT technology, the application of smart devices is becoming increasingly widespread. Most smart devices have the function of storing various types of data, such as collected environmental data and operational data, which are usually stored using flash memory. Flash memory can retain data for a long time even without a current supply, and its storage characteristics are similar to those of a hard drive. It is precisely because of this characteristic that flash memory has become the basis for the storage medium of various portable smart devices. Summary of the Invention
[0003] This application provides a log management method, apparatus, and terminal, which can improve the efficiency of writing and / or reading logs on non-volatile memory, and improve the flexibility of writing and / or reading operations on non-volatile memory. The technical solution is as follows:
[0004] In a first aspect, embodiments of this application provide a log management method, the method comprising:
[0005] The first log modification record is determined in the first storage area of the non-volatile memory;
[0006] Based on the first log modification record item, a target write address is determined, the first log to be saved is obtained, and the first log is written to the second storage area of the non-volatile memory based on the target write address; based on the first log and the first log modification record item, a second log modification record item is determined, and the second log modification record item is stored in the first storage area;
[0007] And / or,
[0008] Based on the first log modification record, a target read address is determined, and the second log to be read is determined. The second log is read from the second storage area of the non-volatile memory based on the target read address. Based on the second log and the first log modification record, a third log modification record is determined and stored in the first storage area.
[0009] Secondly, embodiments of this application provide a log management device, the device comprising:
[0010] The information retrieval module is used to determine the first log modification record item in the first storage area of the non-volatile memory;
[0011] The first update module is configured to determine a target write address based on the first log modification record item, obtain the first log to be saved, write the first log to the second storage area of the non-volatile memory based on the target write address, determine a second log modification record item based on the first log and the first log modification record item, and store the second log modification record item in the first storage area.
[0012] And / or,
[0013] The second update module is used to determine a target read address based on the first log modification record item, determine the second log to be read, read the second log in the second storage area of the non-volatile memory based on the target read address, determine a third log modification record item based on the second log and the first log modification record item, and store the third log modification record item in the first storage area.
[0014] Thirdly, embodiments of this application provide a terminal that may include: a memory and a processor; wherein the memory stores a computer program adapted to be loaded by the memory and execute the above-described method steps.
[0015] The beneficial effects of the technical solutions provided in this application include at least the following:
[0016] In this embodiment, log modification records are used to manage the read and write operations of logs in non-volatile memory. By finding the latest log modification record, the write address of the log to be saved and the read address of the log to be read can be calculated. Therefore, this application can quickly locate the starting point of the position to be written to the log to be saved and the starting point of the position to be read from the log to be read, without traversing the entire log storage space to find the latest position to be written or read. This can improve the efficiency of writing and reading logs in non-volatile memory and increase the flexibility of write and read operations. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a flowchart illustrating a log management method provided in an embodiment of this application;
[0019] Figure 2 This is a flowchart illustrating another log management method provided in an embodiment of this application;
[0020] Figure 3 This is a flowchart illustrating another log management method provided in an embodiment of this application;
[0021] Figure 4 This is a schematic diagram of the structure of a log management device provided in an embodiment of this application;
[0022] Figure 5 This is a schematic diagram of another log management device provided in an embodiment of this application;
[0023] Figure 6 This is a schematic diagram of the structure of another log management device provided in the embodiments of this application.
[0024] Figure 7 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application. Detailed Implementation
[0025] To make the inventive objectives, features, and advantages of the embodiments of this application more apparent and understandable, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0026] In the description of this application, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. In the description of this application, it should be noted that, unless otherwise expressly specified and limited, "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances. Furthermore, in the description of this application, unless otherwise stated, "multiple" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist; for example, A and / or B can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship.
[0027] In related technologies, the common approach to log management in flash memory is to add a timestamp to each log record and then use the timestamp to identify the order in which the logs were stored. However, this method requires traversing the entire log storage space to find the latest log record before determining the corresponding operation location during log write or read operations, resulting in time-consuming and inefficient execution. Another approach is to partition the log records, using partition numbers to locate the areas where log read or write operations are needed. This method, however, suffers from inflexibility.
[0028] The present application will now be described in detail with reference to specific embodiments.
[0029] For ease of explanation, in the following embodiments, only the execution subject of each step is described as the terminal.
[0030] Please see Figure 1 This is a flowchart illustrating a log management method provided in an embodiment of this application. The method in this embodiment may include the following steps:
[0031] S101, determine the first log modification record in the first storage area of the non-volatile memory.
[0032] It is understandable that non-volatile memory refers to flash memory.
[0033] The first storage area refers to the storage area used to store log modification records; the first storage area only stores log modification records.
[0034] The first log modification entry refers to the latest log modification entry in the first storage area. In other words, the first log modification entry is the last log modification entry stored in the first storage area. Log modification entries are usually generated and stored in chronological order. Therefore, the last log modification entry can be understood as the log modification entry whose generation time is the shortest from the current time.
[0035] The first storage area can include multiple log modification entries. Specifically, the first storage area can be a record table where log modification entries are stored. For example, this record table can use a sector-sized storage space, and each log modification entry can occupy 16 bytes, so the record table can store 256 log modification entries. Each log modification entry can mainly include the following: frame header data, write sector number, write sector offset, read sector number, remaining readable length, and checksum data. The log entry includes several key components: a frame header indicating whether the modification was manually written or automatically generated by the system; a write sector label indicating which sector of storage the latest log entry is currently written to; a write sector offset indicating the address offset of the latest log entry within the current sector (e.g., if a sector is 100 bytes and the latest log entry occupies 30 bytes, its address offset is 30, making the write sector offset 30); and a read sector label indicating which sector is currently being read from. The log is divided into several sectors; the read sector offset indicates the address offset of the most recently read log within the current sector. For example, if a sector is 100 bytes in size and the most recently read log occupies 20 bytes of the current sector, then the address offset of that log within the current sector is 20, and the read sector offset would be 20; the remaining readable length indicates how many bytes of log remain unread; and the checksum data is used to verify whether the current log modification entry is valid or whether the information in the log modification entry is accurate.
[0036] In some embodiments, a first log modification entry is determined in a first storage area of the non-volatile memory, which means searching for the latest log modification entry in the first storage area. Specifically, all log modification entries stored in the first storage area can be traversed. During this traversal, these log modification entries can be randomly traversed. Each time a log modification entry is traversed, its frame header data can be obtained, and it can be determined whether the frame header data is a first preset data. For example, the first preset data can be set to 0xA5. If it is the first preset data, it indicates that a log modification entry is stored at the current position. Further, it can be determined whether other log modification entries are stored at positions immediately adjacent to and after the current log modification entry. If other log modification entries are stored, it indicates that the current log modification entry is not the latest log modification entry; if no other log modification entries are stored, it indicates that the current log modification entry is the latest log modification entry. It should be noted that the traversal process can be stopped once the latest log modification entry is found.
[0037] S1021, determine the target write address based on the first log modification record item, obtain the first log to be saved, and write the first log in the second storage area of the non-volatile memory based on the target write address.
[0038] Understandably, the target write address refers to the location in the storage area where the log to be written is to be written; that is, the address in the storage area where the log to be written is to be written.
[0039] The second storage area refers to the storage space used for storing logs. It should be noted that, in this embodiment, the first storage area and the second storage area are different storage areas within the flash memory; the first storage area is used to store log modification records, and the second storage area is used to store the log itself.
[0040] The first log refers to the log that is about to be written to the log storage area (i.e., the second storage area).
[0041] In some embodiments, as described in S101, the latest log modification record stores a write sector number and a write sector offset. Therefore, the sector in which the target write address should be located can be determined based on the write sector number, and the specific location of the target write address within the sector can be determined based on the write sector offset. Specifically, the target write address can be calculated as: Target write address = Sector capacity * Write sector number + Write sector offset. The sector capacity represents the byte capacity of a sector, indicating how many bytes of data a sector can store. Furthermore, the first log can be written starting from the target write address in the second storage area.
[0042] S1022, determine the target read address based on the first log modification record item, determine the second log to be read, and read the second log in the second storage area of the non-volatile memory based on the target read address.
[0043] Understandably, the target read address refers to the position in the storage area where you begin reading logs, that is, the address where you read the stored logs in the storage area.
[0044] The second storage area refers to the storage space used for storing logs. It should be noted that, in this embodiment, the first storage area and the second storage area are different storage areas within the flash memory; the first storage area is used to store log modification records, and the second storage area is used to store the log itself.
[0045] The second log refers to the log that will be read from the log storage area (i.e., the second storage area).
[0046] In some embodiments, as described in S101, the latest log modification record stores a read sector number and a read sector offset. Therefore, the sector in which the target read address should be located can be determined based on the read sector number, and the specific location of the target read address within the sector can be determined based on the read sector offset. The target read address can be calculated as: Target read address = Sector capacity * Read sector number + Read sector offset. The sector capacity represents the byte capacity of a sector, indicating how many bytes of data a sector can store. Furthermore, the second log can be read starting from the target read address in the second storage area.
[0047] Understandably, when determining the second log to be read, it can be read based on a specified number of bytes. This specified number of bytes can be a preset number of bytes. During log read operations, the specified number of bytes of log is read. For example, the specified number of bytes can be set to 60, and each read operation can use 60 bytes of log as the current second log to be read. Alternatively, the second log can be read based on a specified duration. This specified duration can be a preset duration. During log read operations, logs written within the preset duration are read. For example, the specified duration can be the period between the 3rd and 4th hour before the current time, and logs written within this duration can be used as the current second log to be read.
[0048] S1031, determine a second log modification record based on the first log and the first log modification record, and store the second log modification record in the first storage area.
[0049] It is understandable that the second log modification record refers to the latest log modification record in the first storage area after the first log is written.
[0050] In some embodiments, the byte length of the first log can be determined. Further, a new write sector identifier and a new write sector offset can be calculated based on the byte length of the first log and the target write address. It should be noted that for log write operations, when generating the log modification record entry (second log modification record entry) corresponding to the write operation, in addition to calculating the new write sector identifier and the new write sector offset, it is also necessary to calculate the new remaining readable length and the new checksum data. The new remaining readable length can be calculated based on the remaining readable length in the first log modification record entry and the byte length of the first log. The new checksum data can be obtained by XORing the frame header data in the first log modification record entry, the read sector identifier in the first log modification record entry, the read sector offset in the first log modification record entry, the new write sector identifier, the new write sector offset, and the new remaining readable length. Compared to the first log modification entry, the second log modification entry retains the same frame header data, read sector number, and read sector offset, but can use a new write sector number, a new write sector offset, a new remaining readable length, and new checksum data.
[0051] S1032, a third log modification record is determined based on the second log and the first log modification record, and the third log modification record is stored in the first storage area.
[0052] It is understandable that the third log modification record refers to the latest log modification record in the first storage area after the second log is read.
[0053] In some embodiments, the byte length of the second log can be determined first. This byte length can be set by the user before each read operation; alternatively, the user can set a fixed byte length, allowing direct reading of the fixed-byte log during each read operation. Further, a new read sector identifier and a new read sector offset can be calculated based on the byte length of the second log and the target read address. It should be noted that for log read operations, when generating the corresponding log modification record entry (third log modification record entry), in addition to calculating the new read sector identifier and the new read sector offset, it is also necessary to calculate the new remaining readable length and the new checksum data. The new remaining readable length can be calculated based on the remaining readable length in the first log modification record entry and the byte length of the log to be read. The new checksum data can be obtained by XORing the frame header data in the first log modification record entry, the write sector identifier in the first log modification record entry, the write sector offset in the first log modification record entry, the new read sector identifier, the new read sector offset, and the new remaining readable length. Compared to the first log modification entry, the third log modification entry retains the same frame header data, write sector number, and write sector offset, but can use a new read sector number, a new read sector offset, a new remaining readable length, and new checksum data.
[0054] It should be noted that the execution order of S1021 and S1022 is not limited in this embodiment. S1021 and S1022 can be executed simultaneously or at different times. S1021 will always be executed after S1021, and S1022 will always be executed after S1022. When S1021 and S1022 are executed simultaneously, it indicates that the write and read operations of the log management method in this embodiment can be executed concurrently. When S1021 and S1022 are executed at different times, it indicates that the write and read operations of the log management method in this embodiment can be executed at any time.
[0055] In this embodiment, log modification records are used to manage the write operations of logs in non-volatile memory. By finding the latest log modification record, the write address of the first log to be saved and / or the read address of the second log to be read can be calculated. Therefore, this application can quickly locate the starting point of the location to be written to the first log to be saved and / or the starting point of the location to be read to the second log to be read, without traversing the entire log storage space to find the location of the latest log to be written. This can improve the efficiency of writing logs to non-volatile memory and increase the flexibility of write operations.
[0056] Please see Figure 2This is a flowchart illustrating a log management method provided in an embodiment of this application. In this embodiment, the log management method is mainly explained using log write operations. The method described in this embodiment may include the following steps:
[0057] S201, retrieve frame header data corresponding to at least one log modification record item in the first storage area of the non-volatile memory. If the frame header data is first preset data, retrieve the target frame header data corresponding to the address of a preset number of bytes after the frame header data.
[0058] Understandably, descriptions of non-volatile memory, the first storage area, log modification records, frame header data, etc., can be found in [reference needed]. Figure 1 The descriptions in the illustrated embodiments will not be repeated here.
[0059] In some embodiments, the first storage area may store multiple log modification records, among which there is a latest log modification record. During the search for the latest log modification record, the existing log modification records in the first storage area can be traversed sequentially to determine the frame header data of these log modification records, and then the frame header data can be evaluated. For example, after obtaining the frame header data of a log modification record, it can be determined whether the frame header data is a first preset data, which can be set to 0xA5. If the frame header data is the first preset data, the target frame header data stored at the address of a preset number of bytes following the address of the frame header data can be obtained. The preset number of bytes can be set to 16. This is because, in this embodiment, the size of a log modification record is set to 16 bytes. In other embodiments, the size of a log modification record can be set to other byte numbers, and the preset number of bytes can be changed accordingly. This embodiment does not impose any limitations on this.
[0060] Optionally, before performing the steps shown in S201, after the flash is powered on, the flash can be initialized. This may include: initializing the driver interface for accessing the flash chip, such as an SPI or QSPI bus driver; initializing the flash's operating mode, such as configuring the flash read / write mode, using a single-wire or 4-wire method; and initializing the log storage area, such as dividing it into different addresses for storing data with different attributes.
[0061] S202, if the target frame header data is the second preset data, then the log modification record item corresponding to the first preset data is determined to be the first log modification record item.
[0062] In some embodiments, it can be determined whether the target frame header data is the second preset data, which can be set to 0xFF. When the target frame header data is 0xFF, it can be determined that the current position is an idle position, indicating that no log modification record entry has been written to the current position. Then, the previous log modification record entry before the current position is the latest log modification record entry, i.e., the first log modification record entry. At this time, after finding the first log modification record entry, the process of traversing the log modification record entries in S201 can be stopped. It can be understood that if the frame header data in the current log modification record entry is 0xA5, and the target frame header data corresponding to the log modification record entry is also 0xA5, it means that the log modification record entry is not the latest log modification record entry, and the traversal of the log modification record entries in the first storage area can continue.
[0063] S203, obtain the frame header data, write sector number, write sector offset, read sector number, read sector offset, remaining readable length, and checksum data of the first log modification record item, and perform XOR calculation on the frame header data, the write sector number, the write sector offset, the read sector number, the read sector offset, and the remaining readable length to obtain XOR data.
[0064] In some embodiments, an XOR calculation can be performed on each data item in the first log modification record item. Specifically, an XOR calculation can be performed on the frame header data, write sector number, write sector offset, read sector number, read sector offset, remaining readable length, and checksum data to obtain the calculation result, i.e., the XOR data.
[0065] S204, if it is determined that the XOR data is equal to the checksum data, then obtain the write sector number and write sector offset of the first log modification record item.
[0066] S205, calculate the product of the write sector number and the preset sector capacity, calculate the first sum of the product and the write sector offset, and use the first sum as the target write address.
[0067] The following explains S204 to S205.
[0068] In some embodiments, it can be determined whether the XOR data is equal to the checksum data in the first log modification record. If they are equal, it indicates that the first log modification record is valid, meaning that all data in the first log modification record is accurate. Further, the write sector number and write sector offset in the first log modification record can be obtained. The target write address can be obtained using the following formula: First Sum = Write Sector Number * Preset Sector Capacity + Write Sector Offset. The target write address is the first sum. Here, the preset sector capacity refers to the byte capacity of a sector, indicating how many bytes of data a sector can store. For example, the log storage area can be divided into 5 sectors. The write sector offset can be 1 to 100 (integers). Each sector can store 500 bytes of data. The write sector number can be 0 to 4 (integers). A write sector number of 0 can represent the first sector currently being written to the log storage area, a write sector number of 1 can represent the second sector currently being written to the log storage area, a write sector number of 2 can represent the third sector currently being written to the log storage area, and so on. It is easy to understand the meaning of write sector numbers of 3 and 4.
[0069] S206, obtain the first log to be saved, and write the first log to the second storage area of the non-volatile memory based on the target write address.
[0070] In some embodiments, determining the target write address means determining the specific location of the log to be saved in the second storage area where it can be written, specifically which sector and its specific location within that sector. Then, the log to be saved can be written starting from the target write address in the second storage area. Specifically, in this embodiment, when writing the first log, it can be written in the following format: print time + line number + log content. The size of each log entry can be fixed at 27 bytes (including the above three items). The print time records the time the system reached this point, allowing for the inference of the system's historical operating state through chronological order. The line number records the position of the log entry in the software code, facilitating quick problem location for developers or maintenance personnel. The log content can be replaced by a hash value to represent the uniqueness of the log; different logs correspond to different hash values. Before writing each log entry, the log can be input into a hash function to obtain its hash value. Then, the print time + line number + hash value is written to the log storage area. Furthermore, using a hash value to replace the log content reduces the space occupied by the log content and speeds up log storage.
[0071] S207, obtain the write sector offset of the first log modification record item, and determine the remaining sector capacity of the current sector based on the write sector offset and the preset sector capacity.
[0072] Understandably, remaining sector capacity refers to the number of bytes remaining in the current sector that can be used to store logs.
[0073] In some embodiments, the remaining sector capacity = preset sector capacity - write sector offset.
[0074] S208, if the byte length of the first log is greater than the remaining sector capacity, then the sum of the remaining readable length of the first log modification record and the byte length of the first log is taken as the first remaining readable length.
[0075] S209, calculate the first difference between the byte length of the first log and the remaining sector capacity. If the first difference is less than the preset sector capacity, use the first difference as the first write sector offset and increment the write sector number of the first log modification record to obtain the first write sector number.
[0076] The following explains S208 to S209.
[0077] In some embodiments, when the byte length of the first log is greater than the remaining sector capacity, it indicates that the first log needs to be stored across sectors. The first remaining readable length can be calculated as: first remaining readable length = byte length of the first log + remaining readable length in the first log modification record entry; first difference = byte length of the first log - remaining sector capacity. If the first difference is less than the preset sector capacity, the first difference can be used as the first write sector offset, and the first write sector label = write sector label of the first log modification record entry + 1. It can be understood that if the first difference is greater than the preset sector capacity, the quotient and remainder obtained by dividing the first difference by the preset sector capacity can be calculated. In this case, the first write sector offset = remainder, and the first write sector label = write sector label in the first log modification record entry + quotient.
[0078] S210, perform an XOR operation on the first remaining readable length, the first write sector offset, the first write sector label, and the frame header data, read sector label, and read sector offset of the first log modification record item to obtain the first checksum data.
[0079] In some embodiments, the first remaining readable length, the first write sector offset, the first write sector label, the frame header data of the first log modification record, the read sector label of the first log modification record, and the read sector offset of the first log modification record can be XORed to obtain the first checksum data.
[0080] S211, the remaining readable length, write sector offset, write sector number and checksum data of the first log modification record item are replaced with the first remaining readable length, the first write sector offset, the first write sector number and the first checksum data, respectively, to obtain the second log modification record item, and the second log modification record item is stored in the first storage area.
[0081] In some embodiments, for a write operation on the log, a log modification record entry corresponding to the write operation, namely a second log modification record entry, can be generated and stored in a first storage area. Specifically, in generating the log modification record entry corresponding to the write operation, since the read sector number and read sector offset, as well as the frame header data, are not changed during the write operation, the above three data items in the first log modification record entry can still be retained. Therefore, the remaining data items in the first log modification record entry can be replaced. The remaining readable length of the first log modification record entry can be replaced with the first remaining readable length, the write sector offset of the first log modification record entry can be replaced with the first write sector offset, the write sector number of the first log modification record entry can be replaced with the first write sector number, and the checksum data of the first log modification record entry can be replaced with the first checksum data. Therefore, by replacing and retaining the above data, the second log modification record entry can be obtained.
[0082] Optionally, since flash memory can only write data to free pages and cannot overwrite areas with existing data, if the flash log space is completely full and data needs to be written from the beginning, the corresponding sector must be erased before writing. For example, if the current read sector number is 3, indicating that the current read operation is in sector number 3, and a write operation is about to write to sector number 3, the data in sector number 3 must be erased first, and then the data written. In this case, the read sector number in the second log modification record also needs to be modified. The read sector number can be incremented by one because the data in sector number 3 has been erased. To ensure that the read operation reads valid data, the read sector number is incremented so that valid data can be read in sector number 4 during the next read operation.
[0083] S212, if the byte length of the first log is less than or equal to the remaining sector capacity, then the sum of the remaining readable length of the first log modification record and the byte length of the first log is taken as the second remaining readable length.
[0084] In some embodiments, when the byte length of the first log is less than or equal to the remaining sector capacity, it means that the first log does not need to be stored across sectors, the current sector can fully store the first log, and there is no need to change the value of the write sector label. The second remaining readable length can be calculated as the byte length of the first log plus the remaining readable length in the first log modification record.
[0085] S213, the sum of the byte length of the first log and the write sector offset of the first log modification record is used as the second write sector offset.
[0086] In some embodiments, the second write sector offset can be calculated as: the byte length of the first log + the write sector offset of the first log modification record.
[0087] S214, perform an XOR operation on the second remaining readable length, the second write sector offset, and the write sector number, frame header data, read sector number, and read sector offset of the first log modification record to obtain the second checksum data.
[0088] In some embodiments, the second checksum data can be obtained by calculating the XOR operation value among the following six data items: the second remaining readable length, the second write sector offset, the write sector number of the first log modification record, the frame header data of the first log modification record, the read sector number of the first log modification record, and the read sector offset of the first log modification record.
[0089] S215, replace the remaining readable length, write sector offset, and checksum data of the first log modification record item with the second remaining readable length, the second write sector offset, and the second checksum data, respectively, to obtain the second log modification record item, and store the second log modification record item in the first storage area.
[0090] In some embodiments, for a write operation on the log, a log modification record entry corresponding to the write operation, namely a second log modification record entry, can be generated and stored in a first storage area. Specifically, when generating the log modification record entry corresponding to the write operation, since the read sector number, read sector offset, and write sector number, as well as the frame header data, are not changed during the current write operation, the above four data items in the first log modification record entry can still be retained. Therefore, the remaining three data items in the first log modification record entry can be replaced: the remaining readable length of the first log modification record entry can be replaced with the second remaining readable length; the write sector offset of the first log modification record entry can be replaced with the second write sector offset; and the checksum data of the first log modification record entry can be replaced with the second checksum data. Therefore, by replacing and retaining the above data, the second log modification record entry can be obtained.
[0091] In this embodiment, after finding the latest log modification record, its validity can be verified. If the log modification record is valid, the target write address can be determined based on it, and then the log is written at the target write address. This ensures that subsequent write operations are performed only after confirming the data in the previous log modification record is valid and accurate, preventing incorrect writes and guaranteeing the accuracy of data in subsequent log modification records corresponding to the write operation. Therefore, this application can quickly locate the starting point of the log to be written, improving the efficiency of writing logs to non-volatile memory, ensuring that write operations can write valid and accurate data, and storing detailed log information for quick problem identification and analysis of terminal usage, thus improving the flexibility of write operations.
[0092] Please see Figure 3 This is a flowchart illustrating a log management method provided in an embodiment of this application. In this embodiment, the log management method is mainly explained using log read operations. The method described in this embodiment may include the following steps:
[0093] S301, retrieve frame header data corresponding to at least one log modification record item in the first storage area of the non-volatile memory; if the frame header data is first preset data, retrieve the target frame header data corresponding to the address of a preset number of bytes after the frame header data.
[0094] S302, if the target frame header data is the second preset data, then the log modification record item corresponding to the first preset data is determined to be the first log modification record item.
[0095] S303, obtain the frame header data, write sector number, write sector offset, read sector number, read sector offset, remaining readable length, and checksum data of the first log modification record item, and perform XOR calculation on the frame header address, the write sector number, the write sector offset, the read sector number, the read sector offset, and the remaining readable length to obtain XOR data.
[0096] For S301~S303, the execution process and Figure 2 S201 to S203 in the illustrated embodiment are the same; see details below. Figure 2 The descriptions in the illustrated embodiments will not be repeated here.
[0097] S304, if it is determined that the XOR data is equal to the checksum data, then obtain the read sector number and read sector offset from the first log modification record item.
[0098] S305, calculate the product of the read sector number and the preset sector capacity, calculate the second sum of the product and the read sector offset, and use the second sum as the target read address.
[0099] The following explains S304 to S305.
[0100] In some embodiments, it can be determined whether the XOR data is equal to the checksum data in the first log modification record. If they are equal, it indicates that the first log modification record is valid, meaning that all data in the first log modification record is accurate. Further, the read sector number and read sector offset in the first log modification record can be obtained. The target read address can be obtained using the following formula: Second Sum = Read Sector Number * Preset Sector Capacity + Read Sector Offset. The target read address is the second sum. Here, the preset sector capacity refers to the byte capacity of a sector, indicating how many bytes of data a sector can store. For example, the log storage area can be divided into 5 sectors. The value of the read sector offset can be 1 to 100 (integer). Each sector can store 500 bytes of data. The value of the read sector number can be 0 to 4 (integer). The read sector number 0 can represent the first sector currently read in the log storage area. The read sector number 1 can represent the second sector currently read in the log storage area. The read sector number 2 can represent the third sector currently read in the log storage area, and so on. It is easy to understand the meaning of the read sector number 3 and the read sector number 4.
[0101] S306, determine the second log to be read, and read the second log in the second storage area of the non-volatile memory based on the target read address.
[0102] In some embodiments, one specific implementation of this step can be: determining a second log with a target byte length to be read, and reading the second log from a second storage area of non-volatile memory based on the target read address. The target byte length can be variable or fixed. When the target byte length is variable, it means that the target byte length can be set before each read operation, allowing logs of different lengths to be read according to actual needs. When the target byte length is fixed, it means that the user does not need to set the byte length of the log to be read before each read operation, thus simplifying user operations and enabling fast log reading.
[0103] In some embodiments, one specific implementation of this step can be: determining a second log within a target time period to be read, and reading the second log within the target time period from a second storage area of non-volatile memory based on the target read address. The target time period can be variable or fixed. When the target time period is variable, it means that the target time period can be set before each read operation, allowing logs within different time periods to be read according to actual needs. When the target time period is fixed, it means that logs within a fixed time period are read directly during each read operation, simplifying user operations and enabling fast log reading.
[0104] S307, obtain the read sector offset of the first log modification record item, and determine the unread sector capacity of the current sector based on the read sector offset and the preset sector capacity.
[0105] The unread sector capacity refers to the number of unread log bytes remaining in the current sector.
[0106] In some embodiments, the capacity of the sector to be read = preset sector capacity - read sector offset.
[0107] S308, if the byte length of the second log is greater than the capacity of the sector to be read, then the difference between the remaining readable length of the first log modification record and the byte length of the second log is taken as the third remaining readable length.
[0108] S309, calculate the third difference between the byte length of the second log and the capacity of the sector to be read. If the third difference is less than the preset sector capacity, use the third difference as the first read sector offset and increment the read sector number of the first log modification record to obtain the first read sector number.
[0109] Understandably, the byte length of the second log can be set by the user before each read operation; or the user can set a fixed byte length, in which case the fixed byte length log can be read directly during each read operation.
[0110] In some embodiments, when the byte length of the second log is greater than the capacity of the sector to be read, it indicates that the log needs to be read across sectors. The third remaining readable length can be calculated as: the remaining readable length in the first log modification record entry minus the byte length of the second log. The third difference is calculated as: the byte length of the second log minus the capacity of the sector to be read. If the first difference is less than the preset sector capacity, the first difference can be used as the first read sector offset, and the first read sector number is calculated as: the read sector number of the first log modification record entry + 1. It is understood that if the first difference is greater than the preset sector capacity, the quotient and remainder obtained by dividing the first difference by the preset sector capacity can be calculated. In this case, the first read sector offset equals the remainder, and the first read sector number equals: the read sector number in the first log modification record entry + the quotient.
[0111] S310, perform an XOR operation on the first read sector offset, the first read sector label, the third remaining readable length, and the frame header data, write sector label, and write sector offset of the first log modification record item to obtain the third checksum data.
[0112] In some embodiments, the third remaining readable length, the first read sector offset, the first read sector number, the frame header data of the first log modification record, the write sector number of the first log modification record, and the write sector offset of the first log modification record can be XORed to obtain the third checksum data.
[0113] S311, the remaining readable length, read sector number, read sector offset, and checksum data of the first log modification record item are replaced with the third remaining readable length, the first read sector number, the first read sector offset, and the third checksum data, respectively, to obtain the third log modification record item, and the third log modification record item is stored in the first storage area.
[0114] In some embodiments, for a log read operation, a log modification record entry corresponding to the read operation, namely a third log modification record entry, can be generated and stored in the first storage area. Specifically, when generating the log modification record entry corresponding to the read operation, since the write sector number and write sector offset, as well as the frame header data, are not changed during the read operation, the above three data items in the first log modification record entry can still be retained. Therefore, the remaining data items in the first log modification record entry can be replaced. The remaining readable length of the first log modification record entry can be replaced with the third remaining readable length, the read sector offset of the first log modification record entry can be replaced with the first read sector offset, the read sector number of the first log modification record entry can be replaced with the first read sector number, and the checksum data of the first log modification record entry can be replaced with the third checksum data. Therefore, by replacing and retaining the above data, the third log modification record entry can be obtained.
[0115] S312, if the byte length of the second log is less than or equal to the capacity of the sector to be read, then the difference between the remaining readable length of the first log modification record and the byte length of the second log is taken as the fourth remaining readable length.
[0116] In some embodiments, when the byte length of the second log is less than or equal to the capacity of the sector to be read, it means that it is not necessary to read the log across sectors at present, and it is not necessary to change the value of the read sector number. The fourth remaining readable length can be calculated as: the remaining readable length in the first log modification record - the byte length of the second log.
[0117] S313, the sum of the read sector offset of the first log modification record and the byte length of the second log is used as the second read sector offset.
[0118] In some embodiments, the second read sector offset can be calculated as the byte length of the second log plus the read sector offset of the first log modification record.
[0119] S314, perform an XOR operation on the fourth remaining readable length, the second read sector offset, and the read sector number, frame header data, write sector number, and write sector offset of the first log modification record to obtain the fourth checksum data.
[0120] In some embodiments, the fourth remaining readable length, the second read sector offset, the read sector number of the first log modification record, the frame header data of the first log modification record, the write sector number of the first log modification record, and the write sector offset of the first log modification record can be XORed to obtain the fourth checksum data.
[0121] S315, the remaining readable length, read sector offset, and checksum data of the first log modification record item are replaced with the fourth remaining readable length, the second read sector offset, and the fourth checksum data, respectively, to obtain the third log modification record item, and the third log modification record item is stored in the first storage area.
[0122] In some embodiments, for a log read operation, a log modification record entry corresponding to the read operation, namely a third log modification record entry, can be generated and stored in the first storage area. Specifically, when generating the log modification record entry corresponding to the read operation, since the write sector number, write sector offset, and read sector number, as well as the frame header data, are not changed during the current read operation, the above four data items in the first log modification record entry can still be retained. Therefore, the remaining three data items in the first log modification record entry can be replaced: the remaining readable length of the first log modification record entry can be replaced with the fourth remaining readable length; the read sector offset of the first log modification record entry can be replaced with the second read sector offset; and the checksum data of the first log modification record entry can be replaced with the fourth checksum data. Therefore, by replacing and retaining the above data, the fourth log modification record entry can be obtained.
[0123] In this embodiment, after finding the latest log modification record, its validity can be verified. If the log modification record is valid, the target read address can be determined based on it, and then the log is read from the target read address. This ensures that subsequent read operations are performed only after confirming the data in the previous log modification record is valid and accurate, avoiding misreads and guaranteeing the accuracy of data in subsequent log modification records corresponding to the read operation. Therefore, this application can quickly locate the starting point of the log to be read, improving the efficiency of reading logs from non-volatile memory, avoiding misreads, and increasing the flexibility of read operations.
[0124] It should be noted that, in the above Figure 2 and Figure 3 The illustrated embodiments explain the log management method using write and read operations, respectively. In practical applications, during execution... Figure 2 When performing steps S204 to S215, also execute... Figure 3 The steps between S304 and S315 mean that the above log management method can be executed when read / write operations are executed alone, and it can also be executed when read and write operations are executed simultaneously.
[0125] Please see Figure 4 This is a schematic diagram of the structure of a log management device provided in an embodiment of this application. The log management device 400 can be implemented as all or part of a terminal through software, hardware, or a combination of both. The device 400 includes:
[0126] Information lookup module 410 is used to determine the first log modification record item in the first storage area of the non-volatile memory;
[0127] The first update module 420 is configured to determine a target write address based on the first log modification record item, obtain the first log to be saved, write the first log in the second storage area of the non-volatile memory based on the target write address, determine a second log modification record item based on the first log and the first log modification record item, and store the second log modification record item in the first storage area.
[0128] Optionally, the first update module 410 includes:
[0129] The first calculation unit is used to obtain the write sector offset of the first log modification record item and determine the remaining sector capacity of the current sector based on the write sector offset and the preset sector capacity.
[0130] The third calculation unit is used to update the write sector offset, write sector number, remaining readable length and checksum data of the first log modification record item if the byte length of the first log is greater than the remaining sector capacity, so as to obtain the second log modification record item.
[0131] or,
[0132] The fifth calculation unit is used to update the write sector offset, remaining readable length, and checksum data in the first log modification record item if the byte length of the first log is less than or equal to the remaining sector capacity, so as to obtain the second log modification record item.
[0133] Optionally, the third computing unit includes:
[0134] The first determination unit is configured to, if the byte length of the first log is greater than the remaining sector capacity, take the sum of the remaining readable length of the first log modification record item and the byte length of the first log as the first remaining readable length.
[0135] The second judgment unit is used to calculate the first difference between the byte length of the first log and the remaining sector capacity;
[0136] The third judgment unit is used to, if the first difference is less than the preset sector capacity, use the first difference as the first write sector offset and increment the write sector number of the first log modification record item by one to obtain the first write sector number.
[0137] The fourth judgment unit is used to perform an XOR calculation on the first remaining readable length, the first write sector offset, the first write sector number, and the frame header data, read sector number, and read sector offset of the first log modification record item to obtain the first checksum data.
[0138] The fifth judgment unit is used to replace the remaining readable length, write sector offset, write sector number and checksum data of the first log modification record item with the first remaining readable length, the first write sector offset, the first write sector number and the first checksum data, respectively, to obtain the second log modification record item.
[0139] Optionally, the fifth computing unit includes:
[0140] The sixth determination unit is used to, if the byte length of the first log is less than or equal to the remaining sector capacity, take the sum of the remaining readable length of the first log modification record and the byte length of the first log as the second remaining readable length.
[0141] The seventh judgment unit is used to take the sum of the byte length of the first log and the write sector offset of the first log modification record as the second write sector offset.
[0142] The eighth judgment unit is used to perform an XOR calculation on the second remaining readable length, the second write sector offset, and the write sector number, frame header data, read sector number, and read sector offset of the first log modification record item to obtain the second checksum data.
[0143] The ninth judgment unit is used to replace the remaining readable length, write sector offset, and checksum data of the first log modification record with the second remaining readable length, the second write sector offset, and the second checksum data, respectively, to obtain the second log modification record.
[0144] Please see Figure 5 This is a schematic diagram of the structure of a log management device provided in an embodiment of this application. The log management device 500 can be implemented as all or part of a terminal through software, hardware, or a combination of both. The device 500 includes:
[0145] Information lookup module 510 is used to determine the first log modification record item in the first storage area of the non-volatile memory;
[0146] The second update module 520 is configured to determine a target read address based on the first log modification record item, determine the second log to be read, read the second log in the second storage area of the non-volatile memory based on the target read address, determine a third log modification record item based on the second log and the first log modification record item, and store the third log modification record item in the first storage area.
[0147] Optionally, the second update module 520 includes:
[0148] The first reading unit is used to determine the second log of the target byte length to be read, and read the second log of the target byte length in the second storage area of the non-volatile memory based on the target reading address;
[0149] or,
[0150] The second reading unit is used to determine the second log within the target time period to be read, and read the second log within the target time period in the second storage area of the non-volatile memory based on the target reading address.
[0151] Optionally, the second update module 520 includes:
[0152] The second update unit is used to obtain the read sector number and read sector offset from the first log modification record item;
[0153] The fourth update unit is used to calculate the product of the read sector number and the preset sector capacity, calculate the second sum of the product and the read sector offset, and use the second sum as the target read address.
[0154] Optionally, the second update module 520 includes:
[0155] The second calculation unit is used to obtain the read sector offset of the first log modification record item, and determine the sector capacity to be read of the current sector based on the read sector offset and the preset sector capacity.
[0156] The fourth calculation unit is used to update the read sector offset, read sector number, remaining readable length and checksum data of the first log modification record item if the byte length of the second log is greater than the capacity of the sector to be read, so as to obtain the third log modification record item.
[0157] or,
[0158] The sixth calculation unit is used to update the read sector offset, remaining readable length, and checksum data of the first log modification record item if the byte length of the second log is less than or equal to the capacity of the sector to be read, so as to obtain the third log modification record item.
[0159] Optionally, the fourth computing unit includes:
[0160] The first subunit is configured to, if the byte length of the second log is greater than the capacity of the sector to be read, take the difference between the remaining readable length of the first log modification record and the byte length of the second log as the third remaining readable length.
[0161] The second subunit is used to calculate the third difference between the byte length of the second log and the capacity of the sector to be read;
[0162] The third subunit is used to use the third difference as the first read sector offset if the third difference is less than the preset sector capacity, and to increment the read sector number of the first log modification record item by one to obtain the first read sector number.
[0163] The fourth subunit is used to perform an XOR calculation on the first read sector offset, the first read sector number, the third remaining readable length, and the frame header data, write sector number, and write sector offset of the first log modification record item to obtain the third checksum data.
[0164] The fifth subunit is used to replace the remaining readable length, read sector number, read sector offset, and checksum data of the first log modification record item with the third remaining readable length, the first read sector number, the first read sector offset, and the third checksum data, respectively, to obtain the third log modification record item.
[0165] Optionally, the sixth computing unit includes:
[0166] The sixth subunit is used to, if the byte length of the second log is less than or equal to the capacity of the sector to be read, take the difference between the remaining readable length of the first log modification record and the byte length of the second log as the fourth remaining readable length.
[0167] The seventh subunit is used to take the sum of the read sector offset of the first log modification record and the byte length of the second log as the second read sector offset.
[0168] The eighth subunit is used to perform an XOR calculation on the fourth remaining readable length, the second read sector offset, and the read sector number, frame header data, write sector number, and write sector offset of the first log modification record to obtain the fourth checksum data.
[0169] The ninth subunit is used to replace the remaining readable length, read sector offset, and checksum data of the first log modification record with the fourth remaining readable length, the second read sector offset, and the fourth checksum data, respectively, to obtain the third log modification record.
[0170] For further details, please refer to... Figure 6 , Figure 6 This is a schematic diagram of a log management device provided in an embodiment of this application. The log management device 600 can be implemented as all or part of a terminal through software, hardware, or a combination of both. The device 600 includes:
[0171] Information lookup module 610 is used to determine the first log modification record item in the first storage area of the non-volatile memory;
[0172] The first update module 620 is configured to determine a target write address based on the first log modification record item, obtain the first log to be saved, write the first log in the second storage area of the non-volatile memory based on the target write address, determine a second log modification record item based on the first log and the first log modification record item, and store the second log modification record item in the first storage area.
[0173] The second update module 630 is configured to determine a target read address based on the first log modification record item, determine the second log to be read, read the second log in the second storage area of the non-volatile memory based on the target read address, determine a third log modification record item based on the second log and the first log modification record item, and store the third log modification record item in the first storage area.
[0174] It should be noted that the functions of the information search module 610 can be found in [reference needed]. Figure 4 Information search module 410 or Figure 5 For a detailed description of the information retrieval module 510, please refer to the first update module 620. Figure 4 For a detailed description of the first update module 420, see the description of the second update module 620. Figure 5 The specific description of the second update module 520 will not be repeated here.
[0175] Please refer to Figure 7 , Figure 7 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application. Figure 7 As shown, terminal 700 may include: at least one processor 701, at least one network interface 704, user interface 703, memory 705, and at least one communication bus 702.
[0176] The communication bus 702 is used to enable communication between these components.
[0177] The user interface 703 may include a camera, and optionally, the user interface 703 may also include a standard wired interface or a wireless interface.
[0178] The network interface 704 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0179] The processor 701 may include one or more processing cores. The processor 701 connects to various parts within the terminal 700 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 705, and by calling data stored in the memory 705. Optionally, the processor 701 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 701 may integrate one or more of the following: a Central Processing Unit (CPU) and a modem. The CPU primarily handles the operating system and applications. It is understood that the modem may also be implemented as a separate chip, rather than integrated into the processor 701.
[0180] The memory 705 may include random access memory (RAM) or read-only memory. Optionally, the memory 705 may include a non-transitory computer-readable storage medium. The memory 705 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 705 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 705 may also be at least one storage device located remotely from the aforementioned processor 701. Figure 7 As shown, the memory 705, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a program for log management methods.
[0181] exist Figure 7In the terminal 700 shown, the processor 701 can be used to call the program for the log management method stored in the memory 705, and specifically perform the following operations:
[0182] The first log modification record is determined in the first storage area of the non-volatile memory;
[0183] Based on the first log modification record item, a target write address is determined, the first log to be saved is obtained, and the first log is written to the second storage area of the non-volatile memory based on the target write address; based on the first log and the first log modification record item, a second log modification record item is determined, and the second log modification record item is stored in the first storage area;
[0184] And / or,
[0185] Based on the first log modification record, a target read address is determined, and the second log to be read is determined. The second log is read from the second storage area of the non-volatile memory based on the target read address. Based on the second log and the first log modification record, a third log modification record is determined and stored in the first storage area.
[0186] In one embodiment, when processor 701 performs the step of determining the first log modification record in the first storage area of non-volatile memory, it specifically performs the following operations:
[0187] Obtain frame header data corresponding to at least one log modification record in the first storage area of the non-volatile memory;
[0188] If the frame header data is the first preset data, then obtain the target frame header data corresponding to the address of the preset number of bytes located after the frame header data;
[0189] If the target frame header data is the second preset data, then the log modification record item corresponding to the first preset data is determined to be the first log modification record item.
[0190] In one embodiment, before performing the steps of determining the target write address based on the first log modification record entry and / or determining the target read address based on the first log modification record entry, the processor 701 further performs the following operations:
[0191] Obtain the frame header data, write sector number, write sector offset, read sector number, read sector offset, remaining readable length, and checksum data of the first log modification record item;
[0192] The frame header data, the write sector number, the write sector offset, the read sector number, the read sector offset, and the remaining readable length are XORed to obtain the XOR data.
[0193] If it is determined that the XOR data is equal to the checksum data, then the steps of determining the target write address based on the first log modification record item and / or determining the target read address based on the first log modification record item are executed.
[0194] In one embodiment, when processor 701 performs the operation of determining the target write address based on the first log modification record entry, it specifically performs the following operations:
[0195] Obtain the write sector number and write sector offset of the first log modification record;
[0196] Calculate the product of the write sector number and the preset sector capacity, calculate the first sum of the product and the write sector offset, and use the first sum as the target write address.
[0197] In one embodiment, when processor 701 performs the operation of determining the target read address based on the first log modification record entry, it specifically performs the following operations:
[0198] Obtain the read sector number and read sector offset from the first log modification record item;
[0199] Calculate the product of the read sector number and the preset sector capacity, calculate the second sum of the product and the read sector offset, and use the second sum as the target read address.
[0200] In one embodiment, when processor 701 performs the step of determining the second log modification record based on the first log and the first log modification record, it specifically performs the following operations:
[0201] Obtain the write sector offset of the first log modification record item, and determine the remaining sector capacity of the current sector based on the write sector offset and the preset sector capacity.
[0202] If the byte length of the first log is greater than the remaining sector capacity, then the write sector offset, write sector number, remaining readable length and checksum data of the first log modification record are updated to obtain the second log modification record.
[0203] or,
[0204] If the byte length of the first log is less than or equal to the remaining sector capacity, the write sector offset, remaining readable length, and checksum data in the first log modification record are updated to obtain the second log modification record.
[0205] In one embodiment, when processor 701 performs the operation of updating the write sector offset, write sector number, remaining readable length, and checksum data of the first log modification record item if the byte length of the first log is greater than the remaining sector capacity, to obtain the second log modification record item, it specifically performs the following operations:
[0206] If the byte length of the first log is greater than the remaining sector capacity, then the sum of the remaining readable length of the first log modification record and the byte length of the first log is taken as the first remaining readable length.
[0207] Calculate the first difference between the byte length of the first log and the remaining sector capacity;
[0208] If the first difference is less than the preset sector capacity, the first difference is used as the first write sector offset, and the write sector number of the first log modification record is incremented by one to obtain the first write sector number.
[0209] The first remaining readable length, the first write sector offset, the first write sector number, and the frame header data, read sector number, and read sector offset of the first log modification record are XORed to obtain the first checksum data.
[0210] The remaining readable length, write sector offset, write sector number, and checksum data of the first log modification record are replaced with the first remaining readable length, the first write sector offset, the first write sector number, and the first checksum data, respectively, to obtain the second log modification record.
[0211] In one embodiment, when processor 701 performs the operation of updating the write sector offset, remaining readable length, and checksum data in the first log modification record item if the byte length of the first log is less than or equal to the remaining sector capacity, to obtain the second log modification record item, it specifically performs the following operations:
[0212] If the byte length of the first log is less than or equal to the remaining sector capacity, then the sum of the remaining readable length of the first log modification record and the byte length of the first log is taken as the second remaining readable length.
[0213] The sum of the byte length of the first log and the write sector offset of the first log modification record is used as the second write sector offset.
[0214] The second remaining readable length, the second write sector offset, and the write sector number, frame header data, read sector number, and read sector offset of the first log modification record are XORed to obtain the second checksum data.
[0215] The remaining readable length, write sector offset, and checksum data of the first log modification record are replaced with the second remaining readable length, the second write sector offset, and the second checksum data, respectively, to obtain the second log modification record.
[0216] In one embodiment, when processor 701 performs the step of determining the second log to be read and reading the second log in the second storage area of the non-volatile memory based on the target read address, it specifically performs the following operations:
[0217] Determine the target byte length of the second log to be read, and read the target byte length of the second log in the second storage area of the non-volatile memory based on the target read address;
[0218] or,
[0219] Determine the second log within the target time period to be read, and read the second log within the target time period in the second storage area of the non-volatile memory based on the target read address.
[0220] In one embodiment, when processor 701 performs the step of determining the third log modification record based on the second log and the first log modification record, it specifically performs the following operations:
[0221] Obtain the read sector offset of the first log modification record item, and determine the unread sector capacity of the current sector based on the read sector offset and the preset sector capacity;
[0222] If the byte length of the second log is greater than the capacity of the sector to be read, then the read sector offset, read sector number, remaining readable length and checksum data of the first log modification record are updated to obtain the third log modification record.
[0223] or,
[0224] If the byte length of the second log is less than or equal to the capacity of the sector to be read, then the read sector offset, remaining readable length, and checksum data of the first log modification record are updated to obtain the third log modification record.
[0225] In one embodiment, when processor 701 performs the operation of updating the read sector offset, read sector number, remaining readable length, and checksum data of the first log modification record item if the byte length of the second log is greater than the capacity of the sector to be read, to obtain the third log modification record item, it specifically performs the following operations:
[0226] If the byte length of the second log is greater than the capacity of the sector to be read, then the difference between the remaining readable length of the first log modification record and the byte length of the second log is taken as the third remaining readable length.
[0227] Calculate the third difference between the byte length of the second log and the capacity of the sector to be read;
[0228] If the third difference is less than the preset sector capacity, then the third difference is used as the first read sector offset, and the read sector number of the first log modification record is incremented by one to obtain the first read sector number.
[0229] XOR the first read sector offset, the first read sector number, the third remaining readable length, and the frame header data, write sector number, and write sector offset of the first log modification record item to obtain the third checksum data;
[0230] The remaining readable length, read sector number, read sector offset, and checksum data of the first log modification record are replaced with the third remaining readable length, the first read sector number, the first read sector offset, and the third checksum data, respectively, to obtain the third log modification record.
[0231] In one embodiment, when processor 701 executes the step of updating the read sector offset, remaining readable length, and checksum data of the first log modification record item to obtain the third log modification record item if the byte length of the second log is less than or equal to the capacity of the sector to be read, the processor 701 specifically performs the following operations:
[0232] If the byte length of the second log is less than or equal to the capacity of the sector to be read, then the difference between the remaining readable length of the first log modification record and the byte length of the second log is taken as the fourth remaining readable length.
[0233] The sum of the read sector offset of the first log modification record and the byte length of the second log is used as the second read sector offset;
[0234] The fourth remaining readable length, the second read sector offset, and the read sector number, frame header data, write sector number, and write sector offset of the first log modification record are XORed to obtain the fourth checksum data.
[0235] The remaining readable length, read sector offset, and checksum data of the first log modification record are replaced with the fourth remaining readable length, the second read sector offset, and the fourth checksum data, respectively, to obtain the third log modification record.
[0236] In addition, those skilled in the art will understand that the structure of the terminal 700 shown in the above figures does not constitute a limitation on the terminal 700. Smart devices may include more or fewer components than shown, or combine certain components, or have different component arrangements. For example, the terminal 700 also includes radio frequency circuits, audio circuits, WiFi components, power supplies, Bluetooth components, etc., which will not be described in detail here.
[0237] This application also provides a computer-readable storage medium storing at least one instruction, which is executed by a processor to implement the log management method as described in the above embodiments.
[0238] This application also provides a computer program product that stores at least one instruction, which is loaded and executed by the processor to implement the log management method described in the above embodiments.
[0239] Those skilled in the art will recognize that the functions described in the embodiments of this application in one or more of the above examples can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any medium that facilitates the transfer of a computer program from one place to another. Storage media can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0240] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A log management method characterized by comprising: The method comprises: determining a first log modification record item in a first storage area of a non-volatile memory; wherein the first storage area is used for storing at least one log modification record item, the first log modification record item is the latest generated log modification record item, each log modification record item comprises frame header data, write sector label, write sector offset, read sector label, read sector offset, the frame header data is used for finding the first log modification record item; the step of determining the first log modification record item in the first storage area of the non-volatile memory comprises: obtaining the frame header data corresponding to at least one log modification record item in the first storage area of the non-volatile memory; if the frame header data is first preset data, obtaining target frame header data corresponding to the address of a preset byte number located after the frame header data; if the target frame header data is second preset data, determining the log modification record item corresponding to the first preset data as the first log modification record item; determining a target write address based on the write sector label and the write sector offset in the first log modification record item, obtaining a first log to be saved currently, writing the first log in a second storage area of the non-volatile memory based on the target write address; determining a second log modification record item based on the first log and the first log modification record item, and storing the second log modification record item in the first storage area; and / or, determining a target read address based on the read sector label and the read sector offset in the first log modification record item, determining a second log to be read currently, reading the second log in the second storage area of the non-volatile memory based on the target read address; determining a third log modification record item based on the second log and the first log modification record item, and storing the third log modification record item in the first storage area.
2. The method of claim 1, wherein, Before the steps of determining the target write address based on the first log modification record item and / or determining the target read address based on the first log modification record item, the method further comprises: obtaining the frame header data, the write sector label, the write sector offset, the read sector label, the read sector offset, the remaining readable length and the checksum data of the first log modification record item; performing exclusive or calculation on the frame header data, the write sector label, the write sector offset, the read sector label, the read sector offset and the remaining readable length to obtain exclusive or data; if it is determined that the exclusive or data is equal to the checksum data, performing the steps of determining the target write address based on the first log modification record item and / or determining the target read address based on the first log modification record item.
3. The method according to any one of claims 1-2, characterized in that, The step of determining the target write address based on the first log modification record item comprises: obtaining the write sector label and the write sector offset of the first log modification record item; calculating the product of the write sector label and a preset sector capacity, calculating the first sum of the product and the write sector offset, and taking the first sum as the target write address.
4. The method according to any one of claims 1-2, characterized in that, The step of determining the target read address based on the first log modification record item comprises: Obtaining a read sector index and a read sector offset in the first log modification record item; Calculating a product of the read sector index and a preset sector capacity, calculating a second sum value of the product and the read sector offset, and taking the second sum value as a target read address.
5. The method according to any one of claims 1-2, characterized in that, The determining a second log modification record item based on the first log and the first log modification record item comprises: Obtaining a write sector offset of the first log modification record item, and determining a remaining sector capacity of a current sector according to the write sector offset and a preset sector capacity; If the byte length of the first log is greater than the remaining sector capacity, updating the write sector offset, the write sector index, the remaining readable length and the checksum data in the first log modification record item to obtain a second log modification record item; Or, If the byte length of the first log is less than or equal to the remaining sector capacity, updating the write sector offset, the remaining readable length and the checksum data in the first log modification record item to obtain a second log modification record item.
6. The method of claim 5, wherein, If the byte length of the first log is greater than the remaining sector capacity, updating the write sector offset, the write sector index, the remaining readable length and the checksum data in the first log modification record item to obtain a second log modification record item, comprises: If the byte length of the first log is greater than the remaining sector capacity, taking a sum value of the remaining readable length of the first log modification record item and the byte length of the first log as a first remaining readable length; Calculating a first difference value of the byte length of the first log and the remaining sector capacity; If the first difference value is less than a preset sector capacity, taking the first difference value as a first write sector offset, and taking the write sector index of the first log modification record item plus one as a first write sector index; Calculating a first checksum data by performing XOR operation on the first remaining readable length, the first write sector offset, the first write sector index and the frame header data, the read sector index and the read sector offset of the first log modification record item; Replacing the remaining readable length, the write sector offset, the write sector index and the checksum data of the first log modification record item with the first remaining readable length, the first write sector offset, the first write sector index and the first checksum data respectively to obtain a second log modification record item.
7. The method of claim 6, wherein, If the byte length of the first log is less than or equal to the remaining sector capacity, updating the write sector offset, the remaining readable length and the checksum data in the first log modification record item to obtain a second log modification record item, comprises: If the byte length of the first log is less than or equal to the remaining sector capacity, taking a sum value of the remaining readable length of the first log modification record item and the byte length of the first log as a second remaining readable length; Taking a sum value of the byte length of the first log and the write sector offset of the first log modification record item as a second write sector offset; XOR calculating the second remaining readable length, the second write sector offset, and the write sector number, frame header data, read sector number, read sector offset of the first log modification record item, to obtain second checksum data; Replacing the remaining readable length, write sector offset, and checksum data of the first log modification record item with the second remaining readable length, the second write sector offset, and the second checksum data respectively to obtain a second log modification record item.
8. The method of any of claims 1-2, wherein, The determination of the current second log to be read based on the target read address reading the second log in the second storage area of the non-volatile memory comprises: Determining the target byte length of the second log to be read currently, reading the target byte length of the second log in the second storage area of the non-volatile memory based on the target read address; Or, Determining the second log within the target time length to be read currently, reading the second log within the target time length in the second storage area of the non-volatile memory based on the target read address.
9. The method of any of claims 1-2, wherein, The determination of the third log modification record item based on the second log and the first log modification record item comprises: Obtaining the read sector offset of the first log modification record item, and determining the to-be-read sector capacity of the current sector according to the read sector offset and a preset sector capacity; If the byte length of the second log is greater than the to-be-read sector capacity, updating the read sector offset, read sector number, remaining readable length, and checksum data of the first log modification record item to obtain a third log modification record item; Or, If the byte length of the second log is less than or equal to the to-be-read sector capacity, updating the read sector offset, remaining readable length, and checksum data of the first log modification record item to obtain a third log modification record item.
10. The method of claim 9, wherein, If the byte length of the second log is greater than the to-be-read sector capacity, updating the read sector offset, read sector number, remaining readable length, and checksum data of the first log modification record item to obtain a third log modification record item, comprises: If the byte length of the second log is greater than the to-be-read sector capacity, taking the difference between the remaining readable length of the first log modification record item and the byte length of the second log as a third remaining readable length; Calculating a third difference value between the byte length of the second log and the to-be-read sector capacity; If the third difference value is less than a preset sector capacity, taking the third difference value as a first read sector offset, and increasing the read sector number of the first log modification record item by one to obtain a first read sector number; XOR calculating the first read sector offset, the first read sector number, the third remaining readable length, and the frame header data, write sector number, write sector offset of the first log modification record item to obtain third checksum data; replace the remaining readable length, the read sector offset, and the checksum data of the first log modification record item with the third remaining readable length, the first read sector offset, the first read sector offset, and the third checksum data respectively to obtain a third log modification record item.
11. The method of claim 9, wherein, If the byte length of the second log is less than or equal to the capacity of the to-be-read sector, the remaining readable length of the first log modification record item and the difference between the byte length of the second log are taken as a fourth remaining readable length. If the byte length of the second log is less than or equal to the capacity of the to-be-read sector, the remaining readable length of the first log modification record item and the difference between the byte length of the second log are taken as a fourth remaining readable length. The sum of the read sector offset of the first log modification record item and the byte length of the second log is taken as a second read sector offset. The fourth remaining readable length, the second read sector offset, and the read sector offset, the frame header data, the write sector offset, and the write sector offset of the first log modification record item are subjected to XOR calculation to obtain fourth checksum data. The fourth remaining readable length, the second read sector offset, and the fourth checksum data are respectively replaced with the remaining readable length, the read sector offset, and the checksum data of the first log modification record item to obtain a third log modification record item.
12. A log management apparatus characterized by comprising: The apparatus comprises: An information searching module is configured to determine a first log modification record item in a first storage area of a nonvolatile memory; wherein the first storage area is configured to store at least one log modification record item, the first log modification record item is a newly generated log modification record item, each log modification record item comprises frame header data, a write sector offset, a write sector offset, a read sector offset, and a read sector offset, and the frame header data is used to search for the first log modification record item; the determination of the first log modification record item in the first storage area of the nonvolatile memory comprises: obtaining frame header data corresponding to at least one log modification record item in the first storage area of the nonvolatile memory; if the frame header data is first preset data, obtaining target frame header data corresponding to an address located after the frame header data and having a preset number of bytes; if the target frame header data is second preset data, determining that the log modification record item corresponding to the first preset data is the first log modification record item; A first updating module is configured to determine a target write address based on the write sector offset and the write sector offset in the first log modification record item, obtain a first log to be saved, write the first log into a second storage area of the nonvolatile memory based on the target write address, determine a second log modification record item based on the first log and the first log modification record item, and store the second log modification record item in the first storage area; and / or A second updating module is configured to determine a target reading address based on the read sector label and the read sector offset in the first log modification record item, determine a second log to be read currently, read the second log from a second storage area of the non-volatile memory based on the target reading address, determine a third log modification record item based on the second log and the first log modification record item, and store the third log modification record item in the first storage area.
13. A terminal, characterized by comprising: The application further provides a computer program product comprising a computer program which is suitable for loading and executing the method steps of any one of claims 1-11 by a processor and a memory. The application further provides a computer program product comprising a computer program which is suitable for loading and executing the method steps of any one of claims 1-11 by a processor and a memory.
Citation Information
Patent Citations
Continuous data protection and recovery method with log space adjustable online
CN104050268A
Log storage method, log storage device, storage equipment and storage medium
CN114063905A