A file reading method, a computing device, and a readable storage medium
By reading files in chunks, a fixed number of lines of data are read each time and the corresponding data blocks are cached, which solves the problem of long file loading time and achieves fast initialization and efficient display.
Patent Information
- Application Number
- CN202310476873.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-27
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2043-04-27
AI Technical Summary
Existing file viewing tools have long initialization times when loading large files, which may even lead to memory overflow and application crashes.
The method of reading files in blocks is adopted. A fixed number of lines of data are read from the file each time, and the data blocks before and after are cached in the data storage module, including the head and tail cached data blocks. The position information is recorded and updated using a double-ended queue.
It reduces the initialization time for reading very large files to the millisecond level, improves file display speed, and reduces the dependence on file size by ensuring that each data block contains the same number of lines of data.
Smart Images

Figure CN116578539B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computers, and more particularly to a file reading method, a computing device, and a readable storage medium. Background Technology
[0002] Currently, file viewing tools typically load all data from a file into memory first, and then display it using UI controls. In other words, all data in the file must be loaded into memory before displaying it. This obviously leads to longer initialization times, especially noticeable when loading large files. Sometimes, loading large files into memory can even fill up the memory space, causing the application to crash.
[0003] Therefore, a new file reading method is urgently needed to solve the above-mentioned technical problems. Summary of the Invention
[0004] Therefore, the present invention provides a file reading method, a computing device, and a readable storage medium in an attempt to solve or at least alleviate the problems mentioned above.
[0005] According to one aspect of the present invention, a file reading method is provided, suitable for execution in a computing device, the computing device including a data storage module for storing a first predetermined number of currently displayed display data blocks and pre-cached cache data blocks. The method includes: receiving a file reading request; determining whether data is currently stored in the data storage module, the read request including at least a read direction; if so, obtaining the requested target data block from the pre-cached cache data blocks based on the read direction and displaying it; determining the read position of the file based on the read direction; reading a data block from the read position of the file according to the read direction; and updating the data blocks stored in the data storage module based on the read data block, including updating a display data block to cache data block storage, updating the target data block to display data block storage, and updating the read data block to cache data block storage.
[0006] Optionally, in the file reading method according to the present invention, the pre-cached cached data block includes a header cached data block located before the display data block and a tail cached data block located after the display data block. Obtaining the requested target data block from the pre-cached cached data block includes: detecting whether the pre-cached cached data block contains a cached data block on the reading direction side; if so, taking this data block as the target data block and obtaining the target data block.
[0007] Optionally, the file reading method according to the present invention further includes: if there is no data currently stored in the data storage module, then reading a first predetermined number of data blocks from one end of the file based on the reading direction; storing the first predetermined number of data blocks as display data blocks in the data storage module and displaying them; and continuing to read a data block and storing it as a cached data block on the reading direction side in the data storage module.
[0008] Optionally, in the file reading method according to the present invention, the computing device includes a first deque for recording the position information of the endpoints of each data block in the data storage module, and determining the reading position of the file includes: determining the reading position based on the reading direction and the position information recorded in the first deque.
[0009] Optionally, in the file reading method according to the present invention, each data block contains a second predetermined number of lines of data, and the reading direction includes reading towards the head, and reading a data block from the file reading position in the reading direction, including: reading the second predetermined number of lines of data in reverse order from the file reading position towards the head.
[0010] Optionally, in the file reading method according to the present invention, reading a second predetermined number of lines of data in reverse order from the reading position of the file to the head includes: parsing each line of data read in reverse order according to a preset parsing rule; if the parsing is successful, incrementing the number of lines of data read by one; otherwise, keeping the number of lines of data read unchanged; and continuing to read the next line of data to the head until the number of lines of data read reaches the second predetermined number, and then stopping reading.
[0011] Optionally, in the file reading method according to the present invention, updating the data blocks stored in the data storage module includes: releasing the tail cache data block in the data storage module; updating one of the first predetermined number of display data blocks to the tail cache data block; updating the current header cache data block to the display data block; and storing the read data block as the header cache data block in the data storage module.
[0012] Optionally, the file reading method according to the present invention further includes: updating the position information recorded in the first double-ended queue after updating the data block stored in the data storage module.
[0013] Optionally, in the file reading method according to the present invention, the computing device further includes a second deque for recording the position information of the endpoints of each tail buffer data block released and located after a first predetermined number of currently displayed display data blocks. The reading direction further includes reading towards the tail, and reading a data block from the file reading position according to the reading direction, including: if the reading direction is reading towards the tail, determining the end position of reading a data block from the file reading position based on the position information recorded in the second deque; and reading from the file reading position to the end position.
[0014] Optionally, the file reading method according to the present invention further includes: updating the position information recorded in the second double-ended queue after updating the data block stored in the data storage module.
[0015] According to another aspect of the present invention, a computing device is provided, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions including instructions for performing a file reading method according to the present invention.
[0016] According to another aspect of the present invention, a readable storage medium storing program instructions is provided, which, when read and executed by a computing device, causes the computing device to perform a file reading method according to the present invention.
[0017] According to the file reading method of the present invention, the computing device includes a data storage module for storing a first predetermined number of currently displayed display data blocks and pre-cached cache data blocks. Specifically, the method includes receiving a file read request, determining whether data is currently stored in the data storage module, and the read request including at least a read direction. If data is currently stored in the data storage module, the requested target data block is retrieved from the pre-cached cache data blocks based on the read direction and displayed. Subsequently, based on the read direction, the read position of the file is determined, and a data block is read from the read position according to the read direction. Finally, the data blocks stored in the data storage module are updated based on the read data blocks. It can be seen that the present invention employs a block-based file reading method, which can reduce the initialization time for reading very large files to the millisecond level.
[0018] Furthermore, this invention reads a preset number of lines of data from the file each time, rather than dividing the file into several data blocks based on the file size. Therefore, the initialization time is not affected by the file size, and each data block in this invention contains the same number of lines of data.
[0019] In addition to the currently displayed data block, the present invention also caches one data block before and one data block before it in the data storage module. This way, when loading file data later, it can be directly retrieved from the data storage module, thereby improving the file display speed. Attached Figure Description
[0020] To achieve the foregoing and related objectives, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings. These aspects indicate various ways in which the principles disclosed herein may be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The foregoing and other objectives, features, and advantages of this disclosure will become more apparent from the following detailed description, taken in conjunction with the accompanying drawings. Throughout this disclosure, the same reference numerals generally refer to the same parts or elements.
[0021] Figure 1 A structural block diagram of a computing device 100 according to an embodiment of the present invention is shown;
[0022] Figure 2 A flowchart of a file reading method 200 according to an embodiment of the present invention is shown;
[0023] Figure 3 A schematic diagram showing the position information recorded by a first double-ended queue according to an embodiment of the present invention is shown;
[0024] Figure 4 A schematic diagram of a flowchart for reading a data block in reverse order according to an embodiment of the present invention is shown;
[0025] Figure 5 A schematic diagram of a flowchart for reading a row of data in reverse order according to an embodiment of the present invention is shown;
[0026] Figure 6 A schematic diagram of the structure of a list for storing data blocks is shown according to an embodiment of the present invention;
[0027] Figure 7 A schematic diagram showing the position information recorded by a first deque and a second deque according to an embodiment of the present invention is illustrated.
[0028] Figure 8 A schematic diagram showing the updated position information recorded by the first and second deques according to an embodiment of the present invention is illustrated.
[0029] Figure 9 A schematic diagram illustrating a flowchart of the initial reading of log data from a log file according to an embodiment of the present invention is shown;
[0030] Figure 10A schematic diagram of a flowchart for reading log data from a log file for the first time according to an embodiment of the present invention is shown. Detailed Implementation
[0031] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0032] Current file viewing tools require pre-loading all data from a file into memory before displaying it, resulting in long initialization times and impacting user experience. Therefore, file reading can be performed in chunks. For example, when reading a file, it can be divided into several equal-sized chunks based on its size, and then read and displayed in chunks, which can reduce initialization time to some extent. However, this chunking method requires line breaks within each chunk, which is cumbersome, and also suffers from inconsistent content within individual chunks, hindering the use of UI controls.
[0033] Therefore, this invention provides a file reading method suitable for execution in a computing device. Specifically, data is read from the file in blocks, line by line, with a fixed number of lines read and displayed at a time. This eliminates the need for line breaks in the blocks, and each data block contains the same number of lines. Furthermore, in addition to the currently displayed data block, this invention caches the data blocks before and after it in a data storage module. This allows subsequent file data to be retrieved directly from the data storage module, thereby improving file display speed.
[0034] Figure 1 A block diagram of the physical components (i.e., hardware) of a computing device 100 is shown. In a basic configuration, the computing device 100 includes at least one processing unit 102 and a system memory 104. According to one aspect, depending on the configuration and type of the computing device, the processing unit 102 may be implemented as a processor. The system memory 104 includes, but is not limited to, volatile memory (e.g., random access memory), non-volatile memory (e.g., read-only memory), flash memory, or any combination of such memory. According to one aspect, the system memory 104 includes an operating system 105 and a program module 106, the program module 106 including a file reading module 120 configured to execute the file reading method 200 of the present invention.
[0035] According to one aspect, operating system 105 is, for example, suitable for controlling the operation of computing device 100. Furthermore, examples are practiced in conjunction with graphics libraries, other operating systems, or any other applications, and are not limited to any particular application or system. Figure 1 The basic configuration is illustrated by the components within the dashed lines 108. According to one aspect, the computing device 100 has additional features or functions. For example, according to one aspect, the computing device 100 includes additional data storage devices (removable and / or non-removable), such as disks, optical discs, or magnetic tapes. This additional storage... Figure 1 The image is shown by removable storage 109 and non-removable storage 110.
[0036] As stated above, according to one aspect, a program module is stored in system memory 104. According to one aspect, the program module may include one or more applications. The present invention does not limit the type of application; for example, applications may include: email and contact applications, word processing applications, spreadsheet applications, database applications, slideshow applications, drawing or computer-aided applications, web browser applications, etc.
[0037] According to one aspect, examples can be practiced on circuits including discrete electronic components, packaged or integrated electronic chips containing logic gates, circuits utilizing microprocessors, or on a single chip containing electronic components or a microprocessor. For example, it can be practiced via wherein... Figure 1 Each or many of the components shown can be implemented as an example by integrating a System-on-a-Chip (SOC) on a single integrated circuit. According to one aspect, such an SOC device may include one or more processing units, graphics units, communication units, system virtualization units, and various application functions, all integrated (or “burned in”) as a single integrated circuit onto a chip substrate. When operating via the SOC, the functions described herein can be operated via dedicated logic integrated on a single integrated circuit (chip) with other components of the computing device 100. Embodiments of the invention can also be implemented using other techniques capable of performing logical operations (e.g., AND, OR, and NOT), including but not limited to mechanical, optical, fluid, and quantum technologies. Additionally, embodiments of the invention can be implemented within a general-purpose computer or in any other circuit or system.
[0038] According to one aspect, computing device 100 may also have one or more input devices 112, such as a keyboard, mouse, pen, voice input device, touch input device, etc. It may also include output devices 114, such as a display, speaker, printer, etc. The foregoing devices are examples and other devices may also be used. Computing device 100 may include one or more communication connections 116 that allow communication with other computing devices 118. Examples of suitable communication connections 116 include, but are not limited to: RF transmitter, receiver and / or transceiver circuitry; Universal Serial Bus (USB), parallel and / or serial ports.
[0039] As used herein, the term computer-readable medium includes computer storage medium. Computer storage medium can include volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information (e.g., computer-readable instructions, data structures, or program modules). System memory 104, removable storage device 109, and non-removable storage device 110 are examples of computer storage media (i.e., memory storage). Computer storage media can include random access memory (RAM), read-only memory (ROM), electrically erasable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape, magnetic tape, disk storage or other magnetic storage devices, or any other article of manufacture that can be used to store information and is accessible by computer device 100. According to one aspect, any such computer storage medium can be part of computing device 100. Computer storage media does not include carrier waves or other transmitted data signals.
[0040] According to one aspect, a communication medium is implemented by computer-readable instructions, data structures, program modules, or other data in a modulated data signal (e.g., a carrier wave or other transmission mechanism), and includes any information transmission medium. According to one aspect, the term "modulated data signal" describes a signal having one or more sets of characteristics or altered in a manner that encodes information in the signal. By way of example and not limitation, a communication medium includes wired media such as wired networks or direct wired connections, and wireless media such as acoustic, radio frequency (RF), infrared, and other wireless media.
[0041] Figure 2 A flowchart of a file reading method 200 according to an embodiment of the present invention is shown. Method 200 is adapted to be used in a computing device (e.g., Figure 1 The operation is performed in the computing device 100 shown. The computing device includes a data storage module. The data storage module is used to store a first predetermined number of display data blocks currently displayed and pre-cached cache data blocks.
[0042] According to one embodiment of the present invention, two cached data blocks can be pre-cached, specifically a header cached data block preceding the display data block and a tail cached data block following the display data block. Additionally, in some embodiments, each data block can contain a second predetermined number of lines of data. That is, the display data block, the header cached data block, and the tail cached data block all include a second predetermined number of lines of data from the file. According to one embodiment of the present invention, this file can be a log file (i.e., a file storing application or system logs). This is merely an example; other files are also possible, and the present invention does not limit the scope of the application.
[0043] The following example demonstrates reading a 1500-line log file. Specifically, the display interface shows two data blocks in real time (i.e., the UI has two data blocks at all times). The two currently displayed data blocks are display data block 1 and display data block 2. The data in display data block 1 consists of log data from lines 1351 to 1400 in the log file, and the data in display data block 2 consists of log data from lines 1401 to 1450 in the log file (i.e., each data block includes 50 lines of log data). Therefore, the data blocks currently stored in the data storage module include display data block 1, display data block 2, a header cache data block before display data block 1, and a tail cache data block after display data block 2. The data in the header cache data block consists of log data from lines 1301 to 1350 in the log file, and the data in the tail cache data block consists of log data from lines 1451 to 1500 in the log file. It should be noted that this is only an example, and the invention does not limit the first and second predetermined quantities. In specific embodiments, those skilled in the art can make settings according to actual needs.
[0044] like Figure 2 As shown, the file reading method 200 of the present invention begins at 210. In 210, a file read request is received, and it is determined whether data is currently stored in the data storage module. The read request includes at least the read direction.
[0045] If the data storage module currently does not contain any data, indicating this is the first time data is read, then based on the reading direction, a first predetermined number of data blocks are read from one end of the file. The reading direction includes reading towards the head and reading towards the tail. If the reading direction is towards the head, the first predetermined number of data blocks are read from the tail of the file towards the head. If the reading direction is towards the tail, the first predetermined number of data blocks are read from the head of the file towards the tail. Subsequently, the first predetermined number of read data blocks are stored in the data storage module as display data blocks and displayed. Next, one more data block is read and stored in the data storage module as a cached data block for the reading direction. Specifically, if the reading direction is towards the head, one more data block is read towards the head and stored as a head cached data block in the data storage module. If the reading direction is towards the tail, one more data block is read towards the tail and stored as a tail cached data block in the data storage module.
[0046] If the data storage module contains data, it indicates that this is not the first time the data is read. Therefore, if the data storage module contains cached data blocks, then proceed to step 220. Based on the reading direction, retrieve the requested target data block from the pre-cached cached data blocks and display it.
[0047] According to one embodiment of the present invention, the requested target data block can be obtained from a pre-cached cached data block as follows: It is detected whether the pre-cached cached data block contains a cached data block in the read direction. If so, this data block is taken as the target data block and obtained. Otherwise, that is, if the pre-cached cached data block does not contain a cached data block in the read direction, it indicates that all the data in the file has been read, and the process ends.
[0048] Specifically, when reading towards the beginning of the file, the system checks if the pre-cached data blocks contain a header cached data block. If so, the header cached data block is used as the target data block; otherwise, it indicates that the beginning of the file has been reached, and the process ends. Similarly, when reading towards the end of the file, the system checks if the pre-cached data blocks contain a tail cached data block. If so, the tail cached data block is used as the target data block; otherwise, it indicates that the end of the file has been reached, and the process ends.
[0049] Once the requested target data block is retrieved from the pre-cached cached data blocks, the process proceeds to step 230, where the read position of the file is determined based on the read direction. The computing device includes a first deque for recording the position information of the endpoints of each data block in the data storage module. Therefore, according to an embodiment of the present invention, the read position can be determined based on the read direction and the position information recorded in the first deque.
[0050] Specifically, the tail position of the tail cache data block, the tail position of each display data block, the tail position of the head cache data block, and the cached position of the head cache data block can be recorded sequentially from the head to the tail of the first deque. Thus, when reading towards the head, the read position can be determined based on the cached position of the head cache data block recorded in the first deque; when reading towards the tail, the read position can be determined based on the tail position of the tail cache data block recorded in the first deque.
[0051] To better understand this step, let's continue with an example of reading a 1500-line log file. Figure 3 The endpoint position information recorded sequentially from head to tail in the first double-ended queue is as follows: line 1450 (tail position of the tail buffer data block), line 1400 (tail position of a display data block), line 1350 (tail position of a display data block), line 1300 (tail position of the head buffer data block), and line 1250 (the cached position of the head buffer data block). Based on this, it can be deduced that the currently displayed log data consists of lines 1301 to 1400, the log data in the head buffer data block consists of lines 1251 to 1300, and the data in the tail buffer data block consists of lines 1401 to 1450. Therefore, when reading towards the head, line 1250 is determined as the read position; when reading towards the tail, line 1451 is determined as the read position.
[0052] Then, step 240, starting from the file's read position, read a data block according to the read direction. That is, starting from the file's read position, read a second predetermined number of lines of data according to the read direction. Specifically, if the read direction is towards the beginning, read the second predetermined number of lines of data in reverse order from the file's read position towards the beginning. If the read direction is towards the end, read the second predetermined number of lines of data in forward order from the file's read position towards the end.
[0053] During the data block reading process, the read data can be filtered to remove invalid or unnecessary data. Specifically, this can be implemented by filtering each line of data read according to preset rules. The present invention does not limit the preset rules; in specific embodiments, those skilled in the art can set them according to actual needs. The following is combined with... Figure 4 The process of reading a second predetermined number of lines of data in reverse order from the read position of the file to the beginning is explained in the following details.
[0054] Each line of data is read in reverse order and parsed according to preset parsing rules. If parsing is successful, the number of lines read is incremented by one, and the line is saved; otherwise (i.e., parsing fails), the line is determined to be invalid or unnecessary, and is discarded, while the number of lines read remains unchanged. Then, the process continues to read the next line of data in reverse order from the beginning until the number of lines read reaches the second predetermined number, at which point reading stops.
[0055] In some embodiments, a row of data can be read in reverse order as follows. For example... Figure 5 First, one byte of data is read from the determined read position and stored in the character variable `ch`. Then, it is determined whether `ch` is a newline character. If not, the read position is moved forward two bytes, and one byte of data is read from that position and stored in `ch`. This process of determining if `ch` is a newline character continues until `ch` is a newline character. The data between the newline character and the determined read position is then considered a single line of data and read. The reason for moving forward two bytes when `ch` is determined not to be a newline character is that the file descriptor automatically moves forward one byte when reading one byte of data. Therefore, when `ch` is determined not to be a newline character, it needs to be moved forward two bytes from the current read position.
[0056] Furthermore, the process of reading the second predetermined number of lines of data from the file's read position in forward order to the end will not be described in detail here, as it is similar to the process of reading the second predetermined number of lines of data from the file's read position in reverse order to the beginning. For details, please refer to the description above.
[0057] At this point, a data block has been read from the file's read position in the read direction. Subsequently, step 250 is executed, and based on the read data block, the data blocks stored in the data storage module are updated, including updating a display data block to cached data block storage, updating the target data block to display data block storage, and updating the read data block to cached data block storage.
[0058] Specifically, if the reading direction is towards the head, the tail cache data block in the data storage module is released, and one display data block from the first predetermined number of display data blocks is updated to the tail cache data block. Further, the tail display data block from the first predetermined number of display data blocks is updated to the tail cache data block. Next, the current head cache data block (i.e., the target data block) is updated to the display data block, and the read data block is stored in the data storage module as a head cache data block.
[0059] If the read direction is towards the tail, the header cache data block in the data storage module is released, and one display data block from the first predetermined number of display data blocks is updated to the header cache data block. More specifically, the display data block located at the head of the first predetermined number of display data blocks is updated to the header cache data block. Next, the current tail cache data block is updated to the display data block, and the read data block is stored in the data storage module as a tail cache data block.
[0060] According to one embodiment of the present invention, a list can be used to store the data blocks stored in the data storage module. Specifically, the list is divided into three parts: a header cache area for storing header cache data blocks; a data area currently in use for storing a first predetermined number of display data blocks; and a tail cache area for storing tail cache data blocks, such as... Figure 6 As shown.
[0061] To better understand this step, let's take reading a 1500-line log file as an example. Specifically, the current data storage module stores: a header cache data block containing log data from lines 1251 to 1300; display data block 1 containing log data from lines 1301 to 1350; display data block 2 containing log data from lines 1351 to 1400; and a tail cache data block containing log data from lines 1401 to 1450. Therefore, when reading from the header, the log data from lines 1401 to 1450 in the tail cache data block is released. Display data block 2 is stored as a tail cache data block in the tail cache area. The header cache data block is stored as display data block 1, and display data block 1 is stored as display data block 2 in the currently used data area. The read data block is stored as a header cache data block in the header cache area. Thus, the updated data storage module stores: a header cache data block containing log data from lines 1201 to 1250; display data block 1 containing log data from lines 1251 to 1300; display data block 2 containing log data from lines 1301 to 1350; and a tail cache data block containing log data from lines 1351 to 1400.
[0062] When a data block stored in the data storage module changes, the position information recorded in the first double-ended queue should also change accordingly. Therefore, according to one embodiment of the present invention, after the data block stored in the data storage module is updated, the position information recorded in the first double-ended queue also needs to be updated, specifically, it is updated to the position of the endpoints of each data block currently stored in the data storage module.
[0063] Continuing with the example above, before reading data from the head, the endpoint position information recorded from the head to the tail of the first double-ended queue is row 1450, row 1400, row 1350, row 1300, and row 1250, respectively. After reading data from the head, the endpoint position information recorded from the head to the tail of the first double-ended queue is row 1400, row 1350, row 1300, row 1250, and row 1200, respectively.
[0064] Additionally, the log file is explained below. The latest log data is generally stored at the end of the log file; therefore, when reading the log file, it is preferable to read it in reverse order using the method described above. However, during the reverse reading process, users sometimes need to review previously read log data for work purposes. Therefore, in some embodiments, the computing device also includes a second deque for recording the position information of the endpoints of each tail cache data block released and located after the currently displayed first predetermined number of display data blocks. Thus, when the user reviews previously read log data (i.e., reads the file towards the tail), after retrieving and displaying the tail cache data block from the data storage module, the end position of a data block read from the log file's read position can be quickly determined based on the position information recorded in the second deque, and the data can be read from the log file's read position to the end position, and then stored as a tail cache data block in the data storage module.
[0065] The end position for reading a data block from the log file can be determined based on the position information recorded in the second deque. Specifically, the tail positions of each released data block (the head of the second deque records the tail position of the log file) and the tail position of the current tail-buffered data block are recorded sequentially from the head to the tail of the second deque. Thus, the position in the second deque adjacent to the tail position of the tail-buffered data block can be directly used as the end position.
[0066] To better understand this step, let's take reading a 1500-line log file in reverse order as an example. The two data blocks currently displayed are log data from lines 1251 to 1300 and from lines 1301 to 1350, respectively. Therefore, the endpoint positions recorded from the head to the tail of the first double-ended queue should be lines 1400, 1350, 1300, 1250, and 1200, and the endpoint positions recorded from the head to the tail of the second double-ended queue should be lines 1500, 1450, and 1400, respectively. Figure 7 At this point, if a data block is read from the tail, the tail cache data block containing log data from lines 1351 to 1400 will be identified as the target data block and displayed. Subsequently, based on the position information of line 1400 recorded in the first deque, the current read position is determined to be line 1401; based on the position information of lines 1400 and 1450 recorded in the second deque, the end position is determined to be line 1450.
[0067] As mentioned above, when a data block stored in the data storage module is updated, the position information recorded in the first deque must also be updated. Similarly, when a data block stored in the data storage module is updated, the position information recorded in the second deque must also be updated. Specifically, when reading data from the head, the updated tail position of the tail cache data block is added to the tail of the second deque; when reading data from the tail, the position information stored at the tail of the second deque is deleted. That is, when reading data from the head, the position information recorded in the second deque increases, and when reading data from the tail, the position information recorded in the second deque decreases.
[0068] To better understand this step, the following example will be used... Figure 7 The first and second deques are shown as examples. After reading a data block from the tail, the endpoint position information recorded from the head to the tail of the first deque should be rows 1450, 1400, 1350, 1300, and 1250, respectively. The endpoint position information recorded from the head to the tail of the second deque should be rows 1500 and 1450, respectively. Figure 8 .
[0069] To better understand the file reading method of this invention, the following will be combined with... Figure 9 The process of initially reading data from a file will be illustrated using a concrete example. In this example, the file is a log file, and the UI module has two log data blocks (i.e., display data blocks) in real time. Furthermore, the reading direction is from the beginning to the end, meaning the log data is read in reverse order from the end of the log file to the beginning. Specifically:
[0070] The first step is that after receiving the data request from the UI module, the data storage module sends a file read request to the file read module.
[0071] The second step involves the file reading module reading two log data blocks from the log file in reverse order, line by line, based on the received file reading request, and then sending these two log data blocks to the data storage module.
[0072] The third step involves the data storage module storing the two received log data blocks as display data blocks and sending them to the UI module.
[0073] In the fourth step, the file reading module continues to read a log data block from the log file in reverse order, line by line, and sends the log data block to the data storage module.
[0074] Fifth, the data storage module stores the received log data blocks as header cache data blocks.
[0075] The following will combine Figure 10 This example illustrates the process of reading data from a file for the first time. In this example, the file is a log file, and the UI module has two log data blocks in real time, reading from the beginning. Specifically:
[0076] The first step is that after receiving the data request from the UI module, the data storage module sends the header cache data block to the UI module and sends a file read request to the file reading module.
[0077] The second step involves the file reading module reading a log data block from the log file in reverse order, line by line, based on the received file reading request, and then sending the log data block to the data storage module.
[0078] The third step involves the data storage module storing the received log data blocks as header cache data blocks, deleting the log data in the tail cache data blocks (i.e., releasing useless data), and sending a location information update request to the file reading module.
[0079] Fourth, the file reading module updates the queue storing the endpoint position information of the data block (i.e., updates the endpoint position information recorded in the first double-ended queue and the second double-ended queue) and sends a data clearing request to the UI module.
[0080] Fifth, the UI module clears useless log data blocks (that is, it deletes the last log data block from the three log data blocks it currently has).
[0081] According to the file reading method of the present invention, a computing device includes a data storage module for storing a first predetermined number of currently displayed display data blocks and pre-cached cache data blocks. Specifically, the method includes receiving a file read request, determining whether data is currently stored in the data storage module, wherein the read request includes at least a read direction. If data is currently stored in the data storage module, the requested target data block is retrieved from the pre-cached cache data blocks based on the read direction and displayed. Subsequently, based on the read direction, the read position of the file is determined, and a data block is read from the read position of the file according to the read direction. Finally, the data blocks stored in the data storage module are updated based on the read data blocks.
[0082] As can be seen, this invention employs a block-based file reading method, which reduces the initialization time for reading extremely large files to the millisecond level. Furthermore, this invention reads a preset number of lines of data from the file each time, rather than dividing the file into several data blocks based on its size. Therefore, the initialization time is not affected by the file size, and each data block in this invention contains the same number of lines of data.
[0083] Furthermore, in addition to the currently displayed data block, this invention also caches one data block before and one before it in the data storage module. This allows subsequent file data to be retrieved directly from the data storage module, thereby improving file display speed. Additionally, this invention can read files in reverse order, making the reading of log files more convenient.
[0084] The various techniques described herein can be implemented in combination with hardware or software, or a combination thereof. Thus, the methods and apparatus of the present invention, or certain aspects or portions thereof, can take the form of program code (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, USB flash drive, floppy disk, CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into and executed by a machine such as a computer, the machine becomes an apparatus for practicing the present invention.
[0085] When the program code is executed on a programmable computer, the computing device generally includes a processor, a processor-readable storage medium (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store program code; the processor is configured to execute the file reading method of the present invention according to instructions in the program code stored in the memory.
[0086] By way of example, and not limitation, readable media include readable storage media and communication media. Readable storage media stores information such as computer-readable instructions, data structures, program modules, or other data. Communication media generally embodies computer-readable instructions, data structures, program modules, or other data in the form of modulated data signals such as carrier waves or other transmission mechanisms, and includes any information delivery medium. Any combination of the above is also included within the scope of readable media.
[0087] In the specification provided herein, the algorithms and displays are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used with the examples of this invention. The required structure for constructing such systems is apparent from the above description. Furthermore, this invention is not directed to any particular programming language. It should be understood that the contents of the invention described herein can be implemented using various programming languages, and the above description of specific languages is for the purpose of disclosing the best mode of implementation of the invention.
[0088] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.
[0089] It should be understood that, in order to simplify this disclosure and aid in understanding one or more aspects of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof in the above description of exemplary embodiments of the invention. However, this method of disclosure should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim.
[0090] Those skilled in the art will understand that modules, units, or components of the devices disclosed in the examples herein can be arranged in the devices described in this embodiment, or alternatively, can be located in one or more devices different from the devices in this example. The modules in the foregoing examples can be combined into a single module or, in addition, can be divided into multiple sub-modules.
[0091] Those skilled in the art will understand that modules in the device of the embodiments can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiments can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.
[0092] Furthermore, those skilled in the art will understand that although some embodiments described herein include certain features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention and form different embodiments.
[0093] Furthermore, some of the embodiments described herein are methods or combinations of method elements that can be implemented by a processor of a computer system or by other means of performing the functions. Therefore, a processor having the necessary instructions for implementing the methods or method elements forms means for implementing the methods or method elements. Furthermore, the elements described herein in the apparatus embodiments are examples of means for implementing the functions performed by elements for the purposes of carrying out the invention.
[0094] As used herein, unless otherwise specified, the use of ordinal numbers such as “first,” “second,” “third,” etc., to describe ordinary objects merely indicates different instances of similar objects and is not intended to imply that the objects being described must have a given order in time, space, ordering, or any other manner.
[0095] Although the invention has been described with reference to a limited number of embodiments, those skilled in the art will understand from the foregoing description that other embodiments are conceivable within the scope of the invention described herein. Furthermore, it should be noted that the language used in this specification has been chosen primarily for readability and instructional purposes, and not for the purpose of interpreting or limiting the subject matter of the invention. Therefore, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the invention is illustrative and not restrictive, and the scope of the invention is defined by the appended claims.
Claims
1. A file reading method, suitable for execution in a computing device, the computing device including a data storage module, the data storage module being used to store a first predetermined number of currently displayed display data blocks and pre-cached cache data blocks, the method comprising: Receive a read request for the file, determine whether the data storage module currently stores data, and the read request includes at least a read direction, which includes reading towards the header; If so, based on the read direction, the requested target data block is obtained from the pre-cached cached data block and displayed. Based on the reading direction, determine the reading position of the file; Reading a data block from the read position of the file in the read direction, wherein each data block contains a second predetermined number of lines of data, then reading a data block from the read position of the file in the read direction includes: reading the second predetermined number of lines of data in reverse order from the read position of the file towards the beginning; Based on the read data blocks, the data blocks stored in the data storage module are updated, including updating a display data block to cached data block storage, updating the target data block to display data block storage, and updating the read data blocks to cached data block storage; Updating the data blocks stored in the data storage module includes: releasing the tail cache data block in the data storage module; updating one of the first predetermined number of display data blocks to the tail cache data block; updating the current head cache data block to the display data block; and storing the read data block as the head cache data block in the data storage module.
2. The method as described in claim 1, wherein, The pre-cached cached data block includes a header cached data block preceding the display data block and a tail cached data block following the display data block. Obtaining the requested target data block from the pre-cached cached data block includes: Detect whether the pre-cached cached data blocks contain cached data blocks from the read direction side; If so, this data block is used as the target data block, and the target data block is obtained.
3. The method of claim 1 or 2, further comprising: If the data storage module does not currently store any data, then based on the reading direction, a first predetermined number of data blocks are read from one end of the file; The first predetermined number of data blocks are stored as display data blocks in the data storage module and then displayed. as well as Continue reading a data block and store it as a cached data block on the read direction side in the data storage module.
4. The method as described in claim 1 or 2, wherein, The computing device includes a first double-ended queue for recording the position information of the endpoints of each data block in the data storage module, and Determining the read position of the file includes: The reading position is determined based on the reading direction and the position information recorded in the first double-ended queue.
5. The method as described in claim 1 or 2, wherein, Reading a second predetermined number of lines of data in reverse order from the read position of the file towards the beginning, including: Each line of data is read in reverse order and then parsed according to the preset parsing rules; If parsing is successful, increment the number of rows read; otherwise, keep the number of rows read unchanged. Continue reading the next line of data from the head until the number of lines read reaches the second predetermined number, then stop reading.
6. The method of claim 4, further comprising: After updating the data blocks stored in the data storage module, the position information recorded in the first double-ended queue is updated.
7. The method of claim 1, wherein, The computing device further includes a second double-ended queue for recording the position information of the endpoints of each tail cached data block released and located after a first predetermined number of currently displayed display data blocks. The reading direction also includes reading towards the tail. Reading a data block from the read position of the file in the read direction includes: If the reading direction is towards the tail, then based on the position information recorded in the second double-ended queue, the end position of reading a data block from the reading position of the file is determined; Read from the read position to the end position of the file.
8. The method of claim 7, further comprising: After updating the data blocks stored in the data storage module, the position information recorded in the second double-ended queue is updated.
9. A computing device, comprising: At least one processor; as well as A memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions including instructions for performing the method as described in any one of claims 1-8.
10. A readable storage medium storing program instructions that, when read and executed by a computing device, cause the computing device to perform the method as described in any one of claims 1-8.
Citation Information
Patent Citations
Cache reading and reading processing method and device
CN105740166A
File pre-reading method and device based on user space file system FUSE and electronic equipment
CN112181916A