Method, device, equipment and storage medium for file segment storage

By using pre-built files in the preset file queue to store data packets in the file shard storage process, the data packet jitter problem caused by the time overhead of creating folders in the prior art is solved, and the storage efficiency is improved.

CN117785816BActive Publication Date: 2024-11-05柏域信息科技(上海)有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410017734.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-05
Publication Date
2024-11-05
Estimated Expiration
2044-01-05

AI Technical Summary

Technical Problem

In the prior art, when storing files, the time overhead of creating folders and the relatively large packet packet rate, resulting in packet jitter and low storage efficiency.

Method used

By pre-creating several pre-build files, forming a pre-built file queue, and retrieving the pre-built file as the current file storage data packet when needed, avoiding jitter during the creation of the file and improving storage efficiency.

Benefits of technology

It effectively avoids data packet jitter caused by creating files and improves file storage efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117785816B_ABST
    Figure CN117785816B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, equipment and storage medium for file segmentation storage, the method comprising receiving a data packet and extracting data packet information of the data packet; obtaining a current file for storing the data packet, and determining whether the current file has a storage location corresponding to the data packet based on the data packet information and a preset segmentation method; when the storage location corresponding to the data packet does not exist, calling a pre-built file in a preset file queue as the current file, and storing the data packet in the current file. When a new file needs to be created to store a data packet during the file segmentation storage process, the present application forms a new file by calling a pre-built file in a preset file queue, which can avoid jitter caused by creating a file and improve file storage efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of file management technology, and in particular to a method, device, equipment and storage medium for storing file segments. Background Art

[0002] At present, fragmented storage is commonly used when storing files (for example, monitoring files are divided into several file blocks for storage), that is, the collected data packets are stored in fragments, and when a data packet belonging to a new file fragment is received, a new folder needs to be created for the data packet. However, since the time overhead of creating a folder is often an order of magnitude larger than the message rate of the data packet, this will cause data packet jitter when creating a folder and affect the storage efficiency of the data packet.

[0003] Therefore the prior art still needs to be improved and enhanced. Summary of the invention

[0004] The technical problem to be solved by the present application is to provide a method, device, equipment and storage medium for file segment storage in view of the deficiencies in the prior art.

[0005] In order to solve the above technical problems, the first aspect of the present application provides a method for storing file segments, wherein the method for storing file segments specifically includes:

[0006] receiving a data packet and extracting data packet information of the data packet;

[0007] Acquire a current file for storing a data packet, and determine whether the current file has a storage location corresponding to the data packet according to the data packet information and a preset segmentation method;

[0008] When there is no storage location corresponding to the data packet, a pre-built file is retrieved from the preset file queue as the current file, and the data packet is stored in the current file.

[0009] The method for storing file segments, wherein the method comprises:

[0010] Pre-creating a number of pre-built files by creating threads to form a preset file queue, wherein each of the number of pre-built files is an empty file;

[0011] When a pre-built file in a preset file queue is scheduled, the creation thread is triggered to create a pre-built file for the preset file queue.

[0012] The method for storing file segments, wherein the step of pre-creating a plurality of pre-built files by creating a thread to form a preset file queue specifically includes:

[0013] Create several pre-built files by creating threads and obtain the file descriptor of each pre-built file;

[0014] A plurality of pre-built files are added to a preset file queue, and a file descriptor of each pre-built file is stored in a file pool, so that the pre-built file can be scheduled from the preset file queue through the file descriptor.

[0015] The method for storing file segments, wherein the step of retrieving a pre-built file from a preset file queue and scheduling it to the file directory where the current file is located to update the current file specifically includes:

[0016] Reading a file pool for storing file descriptors to obtain a file descriptor of each pre-built file in a preset file queue;

[0017] Select a pre-built file with the earliest build time from all the obtained file descriptors, and use the selected pre-built file as the current file.

[0018] The method for storing file fragments, wherein the data packet information is a data packet timestamp, and the preset fragmentation method is fragmentation by time; and determining whether the current file has a storage location corresponding to a data packet according to the data packet information and the preset fragmentation method specifically comprises:

[0019] Calculate the reference timestamp of the first data packet in the current file, and calculate the interval time between the data packet timestamp and the reference timestamp;

[0020] The length of the time period corresponding to the current file is read, and it is determined whether there is a storage location corresponding to the data packet of the current file according to the length of the time period and the interval time.

[0021] The method for storing file fragments, wherein the data packet information is the space occupied by the data packet, and the preset fragmentation method is fragmentation according to the occupied space capacity; and determining whether the current file has a storage location corresponding to the data packet according to the data packet information and the preset fragmentation method specifically includes:

[0022] Read the remaining storage capacity of the current file;

[0023] Determine whether the current file has a storage location corresponding to the data packet according to the remaining storage capacity and the space occupied by the data packet.

[0024] The method for storing file segments, wherein when there is no storage location corresponding to the data packet, the method further comprises:

[0025] Placing the file descriptor of the current file in a completed file queue, and traversing the completed file queue at preset intervals to determine whether there is a current file that can be closed;

[0026] When there is a closable current file, reading a reference timestamp of a first data packet and a target timestamp of a last data packet in the current file;

[0027] A file name is generated based on the reference timestamp and the target timestamp, and the current file is renamed using the file name.

[0028] A second aspect of the present application provides a file segment storage device, wherein the file segment storage device specifically includes:

[0029] An extraction module, used for receiving a data packet and extracting data packet information of the data packet;

[0030] A determination module, used to obtain a current file for storing a data packet, and determine whether the current file has a storage location corresponding to the data packet according to the data packet information and a preset segmentation method;

[0031] The scheduling module is used to retrieve a pre-built file from a preset file queue as a current file and store the data packet in the current file when there is no storage location corresponding to the data packet.

[0032] A third aspect of the present application provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in any of the file segment storage methods described above.

[0033] A fourth aspect of the present application provides a terminal device, comprising: a processor and a memory;

[0034] The memory stores a computer-readable program executable by the processor;

[0035] When the processor executes the computer-readable program, the steps in any of the above-described methods for storing file segments are implemented.

[0036] Beneficial effects: Compared with the prior art, the present application provides a method, device, equipment and storage medium for file segmentation storage, the method comprising receiving a data packet and extracting data packet information of the data packet; obtaining a current file for storing the data packet, and determining whether the current file has a storage location corresponding to the data packet based on the data packet information and a preset segmentation method; when there is no storage location corresponding to the data packet, retrieving a pre-built file in the preset file queue as the current file, and storing the data packet in the current file. When a new file needs to be created to store a data packet during the file segmentation storage process, the present application forms a new file by retrieving a pre-built file in the preset file queue, which can avoid jitter caused by creating a file and improve file storage efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0038] Figure 1 A flowchart of a method for storing file segments provided in an embodiment of the present application.

[0039] Figure 2 A flowchart of step S20 in the file segment storage provided in an embodiment of the present application.

[0040] Figure 3 A flowchart of a process for constructing a preset file queue in file sharding storage provided in an embodiment of the present application.

[0041] Figure 4 A schematic diagram of the structure of a file sharding storage device provided in an embodiment of the present application.

[0042] Figure 5 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0043] The embodiments of the present application provide a method, device, equipment and storage medium for file segment storage. To make the purpose, technical solution and effect of the present application clearer and more specific, the present application is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0044] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0045] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.

[0046] It should be understood that the sequence numbers and sizes of the steps in this embodiment do not mean the order of execution. The execution order of each process is determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.

[0047] After research, it is found that currently, fragmented storage is commonly used when storing files (for example, monitoring files are divided into several file blocks for storage), that is, the collected data packets are stored in fragments, and when a data packet belonging to a new file fragment is received, a new folder needs to be created for the data packet. However, since the time overhead of creating a folder is often an order of magnitude larger than the message rate of the data packet, this will cause data packet jitter when creating a folder and affect the storage efficiency of the data packet.

[0048] In order to solve the above problems, in an embodiment of the present application, a data packet is received, and the data packet information of the data packet is extracted; a current file for storing the data packet is obtained, and it is determined whether the current file has a storage location corresponding to the data packet based on the data packet information and the preset segmentation method; when the storage location corresponding to the data packet does not exist, a pre-built file is retrieved from the preset file queue as the current file, and the data packet is stored in the current file. When a new file needs to be created to store a data packet during the file segmentation storage process of the present application, a new file is formed by retrieving a pre-built file from the preset file queue, which can avoid jitter caused by creating a file and improve file storage efficiency.

[0049] The application content is further explained below through the description of embodiments in conjunction with the accompanying drawings.

[0050] This embodiment provides a method for storing file segments. Figure 1 As shown, the method includes:

[0051] S10, receiving a data packet, and extracting data packet information of the data packet.

[0052] Specifically, the data packets are received in real time, that is, each time a data packet is received, the data packet information of the data packet is extracted. For example, if the data to be stored in fragments is video surveillance data, then each time a video data frame is collected, the data packet information of the video data frame is extracted. In this way, by extracting the data packet information of each data packet, it is possible to determine whether file fragmentation is required based on the data packet information in the future, thereby improving the accuracy of file fragmentation.

[0053] The data packet information is matched with the file fragmentation method to determine whether file fragmentation is required. That is, the data packet information is determined according to the file fragmentation method, that is, when extracting the data packet information of the data packet, the preset fragmentation method can be read first, and then the data packet information of the data packet can be extracted according to the preset fragmentation method. For example, if the preset fragmentation method is to fragment by time, then the data packet information is the timestamp of the data packet, and if the preset fragmentation method is to fragment by occupied space capacity, then the data packet information is the space occupied by the data packet. Of course, in actual applications, the file fragmentation method can also adopt other methods, such as fragmentation according to the number of data packets, etc., which will not be explained here one by one.

[0054] S20: Acquire a current file for storing a data packet, and determine whether the current file has a storage location corresponding to the data packet according to the data packet information and a preset segmentation method.

[0055] Specifically, the current file is a file used to store the received data packet at the current time, or the current file is a file used to store the data packet received at the previous receiving time corresponding to the data packet. Therefore, obtaining the current file in which the user stores the data packet is to obtain the receiving time of the data packet; then obtaining the previous receiving time of the receiving time, and determining the storage location of the data packet received at the previous receiving time, and finally determining the current file according to the storage location. Of course, in practical applications, other methods can also be used to obtain the current file, for example, by reading the files in the open state among all the files corresponding to the storage thread to obtain the current file, etc.

[0056] After obtaining the current file, it will detect whether the current file is used to store the received data packets, that is, whether to start fragmentation from the data packets. The method of detecting whether to start fragmentation from the data packets is to determine whether there is a storage location for the data packets in the current file according to the data packet information and the preset fragmentation method of the data packets. When there is a storage location for the data packets, it means that no fragmentation operation is required at the data packets, and the data packets can be directly stored in the current file; conversely, when there is no storage location for the data packets, it means that fragmentation operation is required at the data packets, and then the subsequent steps will be executed.

[0057] In one implementation of the embodiment of the present application, the preset slicing method is slicing by time, and the data packet information is the data packet timestamp. Figure 2 As shown, the determining whether the current file has a storage location corresponding to a data packet according to the data packet information and the preset fragmentation method specifically includes:

[0058] S21, calculating the reference timestamp of the first data packet in the current file, and calculating the interval time between the data packet timestamp and the reference timestamp;

[0059] S22: Read the length of the time period corresponding to the current file, and determine whether there is a storage location corresponding to the data packet of the current file according to the length of the time period and the interval time.

[0060] Specifically, the preset slicing method is slicing by time, that is, the received data packets are sliced ​​by time, each slice corresponds to a time period, and the current file is used to store all data packets corresponding to a slice, so that the current file corresponds to a time period. In addition, it is worth noting that the file slicing process is performed in real time during the data packet reception process.

[0061] Furthermore, the first data packet in the current file refers to the earliest data packet stored in the current file, that is, the reference timestamp is the start time of the current file. Therefore, after obtaining the reference timestamp, the interval time between the data packet and the first data packet can be calculated based on the data packet timestamp and the reference timestamp, and then the storage location corresponding to the data packet can be determined based on the interval time and the time period length of the current file. Of course, in actual applications, after obtaining the start time of the current file, the end time of the current file can be determined based on the time period length corresponding to the current file, and then the data packet timestamp of the data packet can be compared with the end time to determine whether the storage location corresponding to the data packet exists in the current file.

[0062] In another implementation of the embodiment of the present application, the preset slicing method is slicing according to occupied space capacity, and the data packet information is the space occupied by the data packet. Accordingly, determining whether the current file has a storage location corresponding to the data packet according to the data packet information and the preset slicing method specifically includes:

[0063] Read the remaining storage capacity of the current file;

[0064] Determine whether the current file has a storage location corresponding to the data packet according to the remaining storage capacity and the space occupied by the data packet.

[0065] Specifically, the preset slicing mode is slicing according to occupied space capacity, which means that when the total space occupied by the data packets stored in the file reaches the preset occupied space capacity, slicing is performed, that is, the data packets received later are stored in new files, so that the total space occupied by the data packets stored in each file is equal to the preset occupied space capacity. Based on this, after extracting the data packet occupied space of the data packet, the remaining storage capacity of the current file is read, wherein the remaining storage capacity is determined according to the preset occupied space capacity and the total space occupied by the data packets included in the current file, that is, the remaining storage capacity = preset occupied space capacity - the total space occupied by the data packets included in the current file.

[0066] After obtaining the remaining storage capacity, the space capacity of the space occupied by the data packet can be compared with the remaining storage capacity. If the space capacity of the space occupied by the data packet is less than the remaining storage capacity, then the storage location corresponding to the data packet does not exist in the current file; conversely, if the space capacity of the space occupied by the data packet is greater than or equal to the remaining storage capacity, then the storage location corresponding to the data packet exists in the current file. Of course, in actual applications, other methods can also be used to determine the storage location, for example, pre-setting the number of data packets corresponding to the current file, and then based on the number of data packets stored in the current file.

[0067] S30: When there is no storage location corresponding to the data packet, a pre-built file is retrieved from a preset file queue as a current file, and the data packet is stored in the current file.

[0068] Specifically, when there is no storage location corresponding to a data packet, it indicates that file segmentation is required, and a storage file needs to be selected for the data packet again. At present, when selecting a storage file, a new creation method is generally adopted. However, since the time overhead required for creating a new file is relatively long compared to the data packet receiving rate, this leads to jitter problems when creating storage files. Therefore, in an embodiment of the present application, when it is necessary to select a storage file for a data packet, a pre-built file will be retrieved from a preset file queue, and then the pre-built file will be used as the current file corresponding to the data packet. In this way, the file creation process and the data packet segmentation storage process can be separated, and the two processes can be performed in parallel through two independent threads, thereby avoiding data packet reception jitter when creating files.

[0069] It should be noted that each pre-built file in the preset file queue is created by creating a thread, that is, in response to a trigger instruction for starting the creation thread, the creation thread is started; a preset number of pre-built files are constructed by the creation thread to form a preset file queue. Based on this, in an implementation of the embodiment of the present application, Figure 3 As shown, the method includes:

[0070] H10. Pre-create several pre-built files by creating threads to form a preset file queue;

[0071] H20. When a pre-built file in a preset file queue is scheduled, the creation thread is triggered to create a pre-built file for the preset file queue.

[0072] Specifically, the creation thread is independent of the file scheduling thread, wherein the creation thread is used to create a pre-built file, and the file scheduling thread is used to receive data packets and allocate storage for the received data packets. The creation thread can pre-build a preset number of pre-built files before the file scheduling thread is started or before file segmentation is performed, and store them in a preset file queue, and then monitor the number of pre-built files in the preset file queue. When the number of files is less than the preset number, the pre-built file will be automatically built so that the preset file queue always has a preset number of pre-built files. This can avoid the problem that the preset queue cannot meet the scheduling thread requirements when the scheduling thread schedules the pre-built files from the preset file queue. In particular, when multiple scheduling threads synchronously perform file reception and segmentation processes, multiple scheduling threads synchronously retrieve pre-built files from the preset file queue. In addition, the preset number of pre-built files in the preset file queue can be set according to actual conditions, for example, 32, 64, etc.

[0073] It should be noted that each of the plurality of pre-built files is an empty file, that is, when creating the pre-built file, the creation thread creates an empty file, which can prevent the pre-built file from occupying storage space.

[0074] Furthermore, in order to facilitate the scheduling of pre-built files, the file descriptors of the pre-built files can be obtained when the pre-built files are built, and the file descriptors of the pre-built files can be centrally stored. Based on this, in an implementation of the embodiment of the present application, the pre-creating of several pre-built files by creating a thread to form a preset file queue specifically includes:

[0075] Create several pre-built files by creating threads and obtain the file descriptor of each pre-built file;

[0076] A plurality of pre-built files are added to a preset file queue, and a file descriptor of each pre-built file is stored in a file pool, so that the pre-built file can be scheduled from the preset file queue through the file descriptor.

[0077] Specifically, the file descriptor is used to locate the pre-built file, that is, the pre-built file can be found through the file descriptor. The file pool is used to store the file descriptor of each pre-built file in the preset file queue, and the pre-built file in the preset file queue can be obtained by searching the file pool. In addition, it should be noted that in order to ensure the matching of the file descriptors in the file pool with the pre-built files in the preset file queue, after the pre-built files in the preset file queue are scheduled, the file descriptors in the file pool are deleted accordingly. This can avoid the situation where the pre-built file cannot be scheduled through the file descriptor.

[0078] Furthermore, when the file descriptor is deleted from the file pool, the file descriptor is added to the preset completed file queue, and it is determined at a preset interval whether there is still data written to the file in the file queue. If there is still written data, the file will not be closed. If there is no written data and the file cannot be closed, the file will wait for the next cycle to close, thereby realizing multi-threaded scheduling and asynchronization. Based on this, in an implementation of the embodiment of the present application, when there is no storage location corresponding to the data packet, the method further includes:

[0079] Placing the file descriptor of the current file in a completed file queue, and traversing the completed file queue at preset intervals to determine whether there is a current file that can be closed;

[0080] When there is a current file that can be closed, reading a reference packet timestamp of a first data packet and a target timestamp of a last data packet in the current file;

[0081] A file name is generated based on the reference packet timestamp and the target timestamp, and the current file is renamed using the file name.

[0082] Specifically, the current file that can be closed needs to meet two conditions, one is that there is no data written, and the other is that it can be closed (that is, there is no scheduling thread to schedule the file). When there is a current file that can be closed, the current file that can be closed will be renamed, wherein the name of the renamed file name includes the reference package timestamp of the first data packet and the target timestamp of the last data packet. Finally, the renamed current file is placed in its corresponding file directory, wherein the file target corresponds to a time period, which is preset, for example, one day, etc. Of course, in actual applications, other naming methods can also be used, for example, using the reference package timestamp of the first data packet, the target timestamp of the last data packet, and the collection address corresponding to the data packet, etc.

[0083] In an implementation of the embodiment of the present application, the calling of a pre-built file in a preset file queue and scheduling it to the file directory where the current file is located to update the current file specifically includes:

[0084] Reading a file pool for storing file descriptors to obtain a file descriptor of each pre-built file in a preset file queue;

[0085] Select a pre-built file with the earliest build time from all the obtained file descriptors, and use the selected pre-built file as the current file.

[0086] Specifically, the preset file queue includes several pre-built files, and the file descriptor of each pre-built file carries the construction time. When selecting the pre-built file, the pre-built file with the earliest construction time can be selected, so that the first-built and the first-tested can be guaranteed. In another implementation, the pre-built file can be selected according to the file purpose in the file descriptor and the purpose of the data packet. For example, if the data packet is video surveillance data, then the pre-built file whose file purpose is to store video data is selected in the preset file queue. That is to say, when pre-building the pre-built file, the file purpose will be configured for each pre-built file, and the file purpose will be stored in the file descriptor, and then the pre-built file will be scheduled from the preset file queue according to the file purpose, so that the purpose of the data packet stored in the file can be quickly determined, which brings convenience to the user. For example, the file purpose can be a backup file, a real-time file, a backup file, a video file, an audio file, and a text file.

[0087] In summary, the present embodiment provides a method, apparatus, device and storage medium for file segmentation storage, the method comprising receiving a data packet and extracting data packet information of the data packet; obtaining a current file for storing the data packet, and determining whether the current file has a storage location corresponding to the data packet based on the data packet information and a preset segmentation method; when there is no storage location corresponding to the data packet, retrieving a pre-built file in the preset file queue as the current file, and storing the data packet in the current file. When a new file needs to be created to store a data packet during the file segmentation storage process, the present application forms a new file by retrieving a pre-built file in the preset file queue, which can avoid jitter caused by creating a file and improve file storage efficiency.

[0088] Based on the above-mentioned file segment storage method, this embodiment provides a file segment storage device, such as Figure 4 As shown, the file fragment storage device specifically includes:

[0089] The extraction module 100 is used to receive a data packet and extract data packet information of the data packet;

[0090] The determination module 200 is used to obtain a current file for storing a data packet, and determine whether the current file has a storage location corresponding to the data packet according to the data packet information and a preset segmentation method;

[0091] The scheduling module 300 is used to retrieve a pre-built file from a preset file queue as a current file and store the data packet in the current file when there is no storage location corresponding to the data packet.

[0092] Based on the above-mentioned file segmentation storage method, this embodiment provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in the file segmentation storage method as described in the above-mentioned embodiment.

[0093] Based on the above file segment storage method, the present application also provides a terminal device, such as Figure 5 As shown, it includes at least one processor (processor) 20; display screen 21; and memory (memory) 22, and may also include a communications interface (Communications Interface) 23 and a bus 24. Among them, the processor 20, the display screen 21, the memory 22 and the communication interface 23 can communicate with each other through the bus 24. The display screen 21 is configured to display a preset user guide interface in the initial setting mode. The communication interface 23 can transmit information. The processor 20 can call the logic instructions in the memory 22 to execute the method in the above embodiment.

[0094] In addition, the logic instructions in the memory 22 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.

[0095] The memory 22 is a computer-readable storage medium that can be configured to store software programs, computer executable programs, such as program instructions or modules corresponding to the methods in the embodiments of the present disclosure. The processor 20 executes functional applications and data processing by running the software programs, instructions or modules stored in the memory 22, that is, implementing the methods in the above embodiments.

[0096] The memory 22 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 22 may include a high-speed random access memory and may also include a non-volatile memory. For example, a variety of media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, may also be a transient storage medium.

[0097] In addition, the specific process of loading and executing the multiple instruction processors in the above-mentioned storage medium and the terminal device has been described in detail in the above-mentioned method, and will not be described one by one here.

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

Claims

1. A method for storing file fragments, characterized in that: The method for storing file segments specifically includes: receiving a data packet and extracting data packet information of the data packet; Acquire a current file for storing a data packet, and determine whether the current file has a storage location corresponding to the data packet according to the data packet information and a preset segmentation method; When there is no storage location corresponding to the data packet, a pre-built file is retrieved from a preset file queue as a current file, and the data packet is stored in the current file; The method further comprises: Pre-creating a number of pre-built files by creating threads to form a preset file queue, wherein each of the number of pre-built files is an empty file; When a pre-built file in a preset file queue is scheduled, triggering the creation thread to create a pre-built file for the preset file queue; Pre-creating a number of pre-built files by creating threads to form a preset file queue specifically includes: Create several pre-built files by creating threads and obtain the file descriptor of each pre-built file; Adding a number of pre-built files to a preset file queue, and storing a file descriptor of each pre-built file in a file pool, so as to schedule the pre-built file from the preset file queue through the file descriptor; Retrieving a pre-built file from a preset file queue and dispatching it to the file directory where the current file is located to update the current file specifically includes: Reading a file pool for storing file descriptors to obtain a file descriptor of each pre-built file in a preset file queue; Select a pre-built file as the current file according to the file purpose in the file descriptor, and the file purpose includes backup file, real-time file, backup file, video file, audio file, and text file; The data packet information is a data packet timestamp, and the preset slicing method is slicing by time; and determining whether the current file has a storage location corresponding to the data packet according to the data packet information and the preset slicing method specifically includes: Calculate the reference timestamp of the first data packet in the current file, and calculate the interval time between the data packet timestamp and the reference timestamp; Reading the length of the time period corresponding to the current file, and determining whether there is a storage location corresponding to the data packet of the current file according to the length of the time period and the interval time; When there is no storage location corresponding to the data packet, the method further includes: Placing the file descriptor of the current file in a completed file queue, and traversing the completed file queue at preset intervals to determine whether there is a current file that can be closed; When there is a closable current file, reading a reference timestamp of a first data packet and a target timestamp of a last data packet in the current file; A file name is generated based on the reference timestamp and the target timestamp, and the current file is renamed using the file name.

2. The method for storing file segments according to claim 1, characterized in that: The step of retrieving a pre-built file from a preset file queue and dispatching it to the file directory where the current file is located to update the current file specifically includes: Reading a file pool for storing file descriptors to obtain a file descriptor of each pre-built file in a preset file queue; Select a pre-built file with the earliest build time from all the obtained file descriptors, and use the selected pre-built file as the current file.

3. The method for storing file segments according to claim 1, characterized in that: The data packet information is the space occupied by the data packet, and the preset slicing method is slicing according to the occupied space capacity; and determining whether the current file has a storage location corresponding to the data packet according to the data packet information and the preset slicing method specifically includes: Read the remaining storage capacity of the current file; Determine whether the current file has a storage location corresponding to the data packet according to the remaining storage capacity and the space occupied by the data packet.

4. A file fragment storage device, characterized in that: The file fragment storage device specifically includes: An extraction module, used for receiving a data packet and extracting data packet information of the data packet; A determination module, used to obtain a current file for storing a data packet, and determine whether the current file has a storage location corresponding to the data packet according to the data packet information and a preset segmentation method; A scheduling module, for retrieving a pre-built file from a preset file queue as a current file when there is no storage location corresponding to the data packet, and storing the data packet in the current file; Pre-creating a number of pre-built files by creating threads to form a preset file queue, wherein each of the number of pre-built files is an empty file; When a pre-built file in a preset file queue is scheduled, triggering the creation thread to create a pre-built file for the preset file queue; Pre-creating a number of pre-built files by creating threads to form a preset file queue specifically includes: Create several pre-built files by creating threads and obtain the file descriptor of each pre-built file; Adding a number of pre-built files to a preset file queue, and storing a file descriptor of each pre-built file in a file pool, so as to schedule the pre-built file from the preset file queue through the file descriptor; Retrieving a pre-built file from a preset file queue and dispatching it to the file directory where the current file is located to update the current file specifically includes: Reading a file pool for storing file descriptors to obtain a file descriptor of each pre-built file in a preset file queue; Select a pre-built file as the current file according to the file purpose in the file descriptor, and the file purpose includes backup file, real-time file, backup file, video file, audio file, and text file; The data packet information is a data packet timestamp, and the preset slicing method is slicing by time; and determining whether the current file has a storage location corresponding to the data packet according to the data packet information and the preset slicing method specifically includes: Calculate the reference timestamp of the first data packet in the current file, and calculate the interval time between the data packet timestamp and the reference timestamp; Reading the length of the time period corresponding to the current file, and determining whether there is a storage location corresponding to the data packet of the current file according to the length of the time period and the interval time; When the storage location corresponding to the data packet does not exist, it also includes: Placing the file descriptor of the current file in a completed file queue, and traversing the completed file queue at preset intervals to determine whether there is a current file that can be closed; When there is a closable current file, reading a reference timestamp of a first data packet and a target timestamp of a last data packet in the current file; A file name is generated based on the reference timestamp and the target timestamp, and the current file is renamed using the file name.

5. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps in the file segment storage method as described in any one of claims 1-3.

6. A terminal device, characterized in that: include: Processor and memory; The memory stores a computer-readable program executable by the processor; When the processor executes the computer-readable program, the steps in the method for file segment storage as described in any one of claims 1 to 3 are implemented.