File storage method, device and electronic equipment

By determining the target storage granularity and storing the files in matching second-class files, the fragmentation problem during small files is solved, efficient utilization of storage space is achieved, and waste is reduced.

CN112579527BActive Publication Date: 2024-12-03BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910943980.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-09-30
Publication Date
2024-12-03
Estimated Expiration
2039-09-30

AI Technical Summary

Technical Problem

The prior art is prone to storage fragmentation when storing small files, resulting in wasted storage space. Especially when small files of different data volumes are integrated into large files and deleted files, it is difficult to effectively utilize the remaining space.

Method used

By obtaining the amount of data of the file to be stored, the target storage granularity is determined, and the file is stored in the second type of file corresponding to the matching storage granularity is used to manage the storage space, ensuring that the file is stored within the same data range. In the same file, reduce the generation of fragments.

Benefits of technology

It effectively reduces the waste of storage space, ensures efficient utilization of storage space, avoids the generation of storage fragments, and improves storage efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112579527B_ABST
    Figure CN112579527B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention provides a file storage method, device and electronic device, including: obtaining a first type of file to be stored as the file to be stored, determining the storage granularity of the file to be stored, and storing the file to be stored in a second type of file corresponding to the target storage granularity. Since the second type of file to store the first type of file is determined based on the data amount of the first type of file, it is ensured that the first type of files with data amounts within the same data amount range will be stored in the same second type of file. Compared with the prior art, the waste of storage space is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of file processing technology, and in particular to a file storage method, device and electronic equipment. Background Art

[0002] With the rapid development of the Internet and the widespread use of various applications such as social networks, mobile communications, online videos, and e-commerce, the data generated has exploded, including a large number of small files with a data volume of less than 1M. Since small files have the characteristics of small data volume and large number, the storage of massive small files has become a recognized problem in the industry.

[0003] In the prior art, a large number of small files are usually randomly integrated into a large file with a data volume greater than or equal to 1M for storage. For example, if there are four small files with data volumes of 512K, 256K, 128K, and 128K respectively, these four small files can be integrated into a large file with a data volume of 1M, and then the large file can be stored.

[0004] In the process of implementing the present invention, the inventors found that the prior art has at least the following problems:

[0005] In the prior art, small files with different data volumes are randomly integrated into a large file. In the subsequent operation process of the large file, storage fragments are easily generated, thereby causing a large amount of storage space to be wasted. For example, in a large file, multiple small files with data volumes of 4K, 5K, 7K and 8K are stored. When a small file with a data volume of 7K is deleted, a storage space with a storage capacity of 7K is generated. The storage space can only store small files with a data volume less than or equal to 7K. When the storage space stores a small file of 4K, the remaining 3K storage space is difficult to be used, thereby generating a 3K storage fragment. Summary of the invention

[0006] The purpose of the embodiments of the present invention is to provide a small file storage method, device and electronic device to reduce the waste of storage space. The specific technical solution is as follows:

[0007] An embodiment of the present invention provides a file storage method, including:

[0008] Acquire a first type of file to be stored as the file to be stored, and determine the data volume of the file to be stored, wherein the first type of file is a file whose data volume is not greater than a first preset threshold;

[0009] Determine a storage granularity matching the data amount according to the data amount as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of files, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of files; wherein the second type of files are files whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold;

[0010] The files to be stored are stored in a second type of files corresponding to the target storage granularity.

[0011] Furthermore, for each storage granularity, the storage granularity corresponds to a plurality of second-type files whose storage space is divided according to the storage granularity;

[0012] The storing the to-be-stored file in a second type of file corresponding to the target storage granularity includes:

[0013] Determining, among the plurality of second-category files corresponding to the target storage granularity, a second-category file for storing the file to be stored as a first target file;

[0014] The file to be stored is stored in the first target file.

[0015] Furthermore, among the plurality of second-category files corresponding to the target storage granularity, the second-category file for storing the file to be stored is determined as the first target file, including:

[0016] Acquire a free file index table corresponding to the target storage granularity, wherein the free file index table is used to record first identification information of second-category files corresponding to the target storage granularity and having storage space in an idle state;

[0017] Among the multiple second-category files, a second-category file identified by the first identification information recorded in the free file index table is determined as the first target file.

[0018] Furthermore, after obtaining the free file index table corresponding to the target storage granularity, the method further includes:

[0019] If the record in the free file index table is empty, a second type of file corresponding to the target storage granularity is created according to the target storage granularity, and the first identification information of the second type of file is written into the free file index table.

[0020] Further, storing the file to be stored in the first target file includes:

[0021] Acquire a free storage space index table of the first target file, wherein the free storage space index table records second identification information of storage spaces in a free state in the storage spaces into which the first target file is divided;

[0022] Determine, according to the second identification information recorded in the free storage space index table, a storage space in an idle state as the free storage space;

[0023] The file to be stored is stored in the free storage space.

[0024] Furthermore, after storing the file to be stored in the free storage space, the method further includes:

[0025] Obtaining identification information of the file to be stored as third identification information;

[0026] The first identification information of the first target file, the second identification information of the free storage space, and the third identification information are associated and written into a preset first-category file index table.

[0027] Furthermore, the method further comprises:

[0028] When a deletion operation for a first category of files to be deleted is received, determining a second category of files storing the first category of files to be deleted as a second target file;

[0029] In the second target file, the first type of files to be deleted are deleted.

[0030] An embodiment of the present invention further provides a file storage device, the device comprising:

[0031] A file acquisition module, used to acquire a first type of file to be stored as the file to be stored, and determine the data volume of the file to be stored, wherein the first type of file is a file whose data volume is not greater than a first preset threshold;

[0032] a storage granularity determination module, configured to determine, according to the data volume, a storage granularity matching the data volume as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of files, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of files; wherein the second type of files are files whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold;

[0033] The file storage module is used to store the file to be stored in a second type of file corresponding to the target storage granularity.

[0034] Furthermore, for each storage granularity, the storage granularity corresponds to a plurality of second-type files whose storage space is divided according to the storage granularity;

[0035] The file storage module specifically determines, among the multiple second-category files corresponding to the target storage granularity, a second-category file for storing the file to be stored as a first target file, and stores the file to be stored in the first target file.

[0036] Furthermore, the file storage module is specifically used to obtain a free file index table corresponding to the target storage granularity, wherein the free file index table is used to record first identification information of second-category files corresponding to the target storage granularity and having storage space in an idle state, and among the multiple second-category files, the second-category file identified by the first identification information recorded in the free file index table is determined as the first target file.

[0037] Furthermore, the file storage module is also used to create a second type of file corresponding to the target storage granularity according to the target storage granularity if the record in the free file index table is empty, and write the first identification information of the second type of file into the free file index table.

[0038] Furthermore, the file storage module is specifically used to obtain a free storage space index table of the first target file, wherein the free storage space index table records second identification information of the storage space in the storage space divided by the first target file and is in an idle state, and based on the second identification information recorded in the free storage space index table, the storage space in an idle state is determined as the free storage space, and the file to be stored is stored in the free storage space.

[0039] Furthermore, the device also includes:

[0040] An information writing module is used to obtain identification information of the file to be stored as third identification information after the file storage module stores the file to be stored in the free storage space, and to write the first identification information of the first target file, the second identification information of the free storage space and the third identification information into a preset first-category file index table in an associated manner.

[0041] Furthermore, the device also includes:

[0042] The file deletion module is used for, when receiving a deletion operation for a first type of file to be deleted, determining a second type of file storing the first type of file to be deleted as a second target file, and deleting the first type of file to be deleted in the second target file.

[0043] An embodiment of the present invention further provides an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0044] Memory, used to store computer programs;

[0045] The processor is used to implement the steps of any of the above-mentioned file storage methods when executing the program stored in the memory.

[0046] The present invention also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned file storage methods are implemented.

[0047] An embodiment of the present invention also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute any of the above-mentioned file storage methods.

[0048] A small file storage method, device and electronic device provided by an embodiment of the present invention, in which a first type of file to be stored is obtained as the file to be stored, and the data amount of the file to be stored is determined, wherein the first type of file is a file whose data amount is not greater than a first preset threshold, and a storage granularity matching the data amount is determined according to the data amount as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of file, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of file; wherein the second type of file is a file whose storage capacity is not less than a second preset threshold, the first preset threshold is less than the second preset threshold, and the file to be stored is stored in the second type of file corresponding to the target storage granularity, because the second type of file storing the first type of file is determined based on the data amount of the first type of file, thereby ensuring that the first type of files with data amounts within the same data amount range will be stored in the same second type of file, when a first type of file is deleted, the storage space of the first type of file is vacated to store only the first type of files with a data amount not much different from the first type of file, thereby controlling the size of the storage fragments that may appear to a certain extent, and reducing the waste of storage space compared to the prior art.

[0049] Of course, it is not necessary to achieve all of the above advantages at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.

[0051] Figure 1A flowchart of a file storage method provided by an embodiment of the present invention;

[0052] Figure 2 A flowchart of another file storage method provided by one embodiment of the present invention;

[0053] Figure 3 A flowchart of a method for determining a target file provided by an embodiment of the present invention;

[0054] Figure 4 A flowchart of another file storage method provided by another embodiment of the present invention;

[0055] Figure 5 A flowchart of a file deletion method provided by an embodiment of the present invention;

[0056] Figure 6 A schematic diagram of the structure of a file storage device provided by an embodiment of the present invention;

[0057] Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0058] In order to provide an implementation scheme to reduce the waste of storage space, the embodiments of the present invention provide a file storage method, device and electronic device, and the embodiments of the present invention are described below in conjunction with the drawings of the specification. In addition, the embodiments and features in the embodiments of the present application can be combined with each other if there is no conflict.

[0059] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0060] In one embodiment of the present invention, a file storage method is provided, such as Figure 1 As shown, the method comprises the following steps:

[0061] S101: Acquire a first type of file to be stored as the file to be stored, and determine the data volume of the file to be stored.

[0062] In this step, the first category of files is files whose data volume is not greater than a first preset threshold.

[0063] In one embodiment, after receiving a file storage operation, a first type of file to be stored can be obtained, wherein the first preset threshold can be determined based on actual usage scenarios and requirements combined with experience. In one embodiment, the first preset threshold can be 1M (i.e. 1024K). At this time, the first type of file can be a small file.

[0064] In one embodiment, the data volume of the file to be stored may be determined by reading the file attribute of the file to be stored. Exemplarily, the data volume of the file to be stored may be 10K.

[0065] S102: Determine a storage granularity that matches the data volume according to the data volume as the target storage granularity.

[0066] In this step, the target storage granularity is used to divide the storage space of the second type of files, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of files.

[0067] The second type of files are files whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold.

[0068] The above storage capacity is the maximum amount of data that the second file can store, wherein the first preset threshold is less than the second preset threshold. In one embodiment, the second preset threshold may be determined based on actual usage scenarios and requirements combined with experience. In one embodiment, the second preset threshold may be greater than 1M. In order to better store small files, the second preset threshold may be 100M.

[0069] In one embodiment, the storage granularity may represent the size of each storage space obtained by dividing the storage space of the second type of files. For example, if the storage granularity is 16K, it means that the size of each storage space obtained by dividing the storage space of the second type of files is 16K.

[0070] In one embodiment, the storage granularity matching the data volume may be determined in the following manner, but is not limited thereto:

[0071] Among multiple preset data volume ranges, determine the data volume range to which the data volume belongs as the target data volume range, wherein the multiple data volume ranges do not overlap with each other, and based on the correspondence between the preset data volume range and the storage granularity, determine the storage granularity corresponding to the target data volume range among multiple storage granularities as the target storage granularity, wherein the storage granularity represents the size of the storage capacity.

[0072] In one embodiment, multiple preset data volume ranges may be determined based on actual usage scenarios and requirements combined with experience.

[0073] In one embodiment, when the first preset threshold is 1024K, the following 10 data volume ranges can be preset: (0, 2], (2, 4], (4, 8], (8, 16], (16, 32], (32, 64], (64, 128], (128, 256], (256, 512], and (512, 1024].

[0074] Exemplarily, when the data volume of the file to be stored is 15K, it can be determined that the data volume of the file to be stored is between 8K and 16K, that is, the data volume range to which the data volume of the file to be stored belongs is (8, 16], and the data volume range (8, 16] is used as the target data volume range.

[0075] In one embodiment, the data lengths of the data amount ranges may be the same. For example, multiple data amount ranges may be preset in the manner of (0, 2], (2, 4], (4, 6], and (6, 8] to ensure that the data length of each data amount is 2.

[0076] In one embodiment, the storage granularity can be divided into 2K, 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K and 1024K, and the data volume range corresponding to the 2K storage granularity can be preset as (0, 2], the data volume range corresponding to the 4K storage granularity is (2, 4], the data volume range corresponding to the 8K storage granularity is (4, 8], the data volume range corresponding to the 16K storage granularity is (8, 16], the data volume range corresponding to the 32K storage granularity is (16, 32], the data volume range corresponding to the 64K storage granularity is (32, 64], the data volume range corresponding to the 128K storage granularity is (64, 128], the data volume range corresponding to the 256K storage granularity is (128, 256], the data volume range corresponding to the 512K storage granularity is (256, 512] and the data volume range corresponding to the 1024K storage granularity is (512, 1024].

[0077] As in the above embodiment, the target data volume range is the data volume range (8, 16], and the storage granularity corresponding to the data volume range (8, 16] is 16K, and the storage granularity 16K is determined as the target storage granularity.

[0078] S103: storing the file to be stored in a second type of file corresponding to the target storage granularity.

[0079] In this step, each storage granularity may correspond to a second-class file. Exemplarily, there are three storage granularities of 2K, 4K and 6K, which correspond to the second files respectively. The second-class files include files A, B and C, whose storage capacity is 100M. The target storage granularity matching the file to be stored is 4K. Since the target storage granularity is 4K and corresponds to file B, the file to be stored may be stored in file B. Similarly, when the target storage granularity matching the file to be stored is 2K, it is stored in file A. When the target storage granularity matching the file to be stored is 6K, it is stored in file C. Thus, it can be ensured that the difference between the first-class files stored in files A, B and C is within the range of 2K, that is, in the most special case, for each storage space, a maximum of 2K storage fragments are generated. Moreover, the possible size of the storage fragments can be adjusted by adjusting the data volume range. Furthermore, because multiple second-class files can exist at the same time, the storage efficiency of the first-class files is also improved to a certain extent.

[0080] In the above-mentioned file storage method provided by the embodiment of the present invention, a first type of file to be stored is obtained as the file to be stored, and the data amount of the file to be stored is determined, wherein the first type of file is a file whose data amount is not greater than a first preset threshold, and a storage granularity matching the data amount is determined according to the data amount as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of file, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of file; wherein the second type of file is a file whose storage capacity is not less than a second preset threshold, the first preset threshold is less than the second preset threshold, and the file to be stored is stored in The second type of file is stored in a second type of file corresponding to the target storage granularity, wherein the second type of file is a file whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold. Since the second type of file storing the first type of file is determined based on the data volume of the first type of file, it is ensured that the first type of files with data volumes within the same data volume range will be stored in the same second type of file. When a first type of file is deleted, the storage space of the first type of file is vacated to store only the first type of files with a data volume not much different from that of the first type of file, thereby controlling the size of possible storage fragments to a certain extent and reducing the waste of storage space compared to the prior art.

[0081] In one embodiment, for each storage granularity, the storage granularity may correspond to a plurality of second-type files whose storage space is divided according to the storage granularity, that is, the second-type files are logically divided into a plurality of storage spaces according to the storage granularity. Exemplarily, the second-type files include file A and file B, and the corresponding storage granularities are 2K and 4K respectively, then file A is logically divided into a plurality of storage spaces with a storage capacity of 2K, and file B is logically divided into a plurality of storage spaces with a storage capacity of 4K.

[0082] In one embodiment, each divided storage space is only used to store one first-category file. Furthermore, the Chunk technology can be used to implement the storage space division of the second-category files, and the storage granularity is the ChunkSize in the Chunk technology.

[0083] Based on the above embodiment, the embodiment of the present invention also provides another file storage method to implement the above step S103, such as Figure 2 As shown, the steps include:

[0084] S201: Determine, among a plurality of second-category files corresponding to a target storage granularity, a second-category file for storing a file to be stored as a first target file.

[0085] In this step, based on a preset first determination rule, a second type of file for storing the file to be stored may be determined from a plurality of second type of files corresponding to the target storage granularity, wherein the first determination rule may be determined based on factors such as demand or experience.

[0086] In one embodiment, the preset first determination rule may be to randomly determine a second category file for storing the file to be stored among multiple second category files corresponding to the target storage granularity, and may also determine the second category file with the smallest data volume as the large file for storing the file to be stored.

[0087] Exemplarily, the target storage granularity corresponds to three second-category files, namely files A, B and C. Then, a file A can be randomly determined from files A, B and C to be selected as the second-category file for storing the files to be stored, and file A is used as the first target file.

[0088] S202: Store the file to be stored in a first target file.

[0089] In this step, the file to be stored may be stored in the first target file.

[0090] In the above-mentioned another file storage method provided by an embodiment of the present invention, a second type file for storing the file to be stored can be determined from among multiple second type files corresponding to the target storage granularity as the first target file, and the file to be stored can be stored in the first target file. A second type file for storing the file to be stored can be determined from among multiple second type files.

[0091] Furthermore, the embodiment of the present invention also provides a target file determination method to implement the above step S201, such as Figure 3 As shown, the steps include:

[0092] S301: Obtain a free file index table corresponding to the target storage granularity.

[0093] In this step, the above-mentioned free file index table is used to record the first identification information of the second category files corresponding to the target storage granularity and having storage space in an idle state. It can be pre-established or updated in real time with operations such as addition and deletion. In one embodiment, the first identification information can be the file name of the second category file, or it can be information such as the file path of the second category file.

[0094] In one embodiment, the free file index table can record the mapping relationship between the storage granularity and the corresponding target storage granularity, and the second type of files in the storage space in the idle state. Through the free file index table, the second type of files with free storage space corresponding to different storage granularities can be quickly and conveniently determined.

[0095] In one embodiment, if the record in the free file index table is empty, a second type of file corresponding to the target storage granularity may be created according to the target storage granularity, and the first identification information of the second type of file may be written into the free file index table.

[0096] S302: Determine, among multiple second-category files, a second-category file identified by first identification information recorded in a free file index table as a first target file.

[0097] In this step, when there are multiple second-category files identified by the first identification information recorded in the free file index table, one of the second-category files identified by the first identification information recorded in the free file index table can be randomly determined as the first target file. Alternatively, in order to ensure storage balance, the second-category file with the smallest data volume can be determined as the first target file among the multiple identified second files.

[0098] Exemplarily, the second category of files identified by the first identification information recorded in the free file index table include A, B, and C, and then file A can be randomly determined among files A, B, and C as the first target file.

[0099] In the above-mentioned target file determination method provided by an embodiment of the present invention, a free file index table corresponding to the target storage granularity can be obtained, wherein the free file index table is used to record the first identification information of the second category file corresponding to the target storage granularity and having storage space in an idle state, and among multiple second category files, the second category file identified by the first identification information recorded in the free file index table is determined as the first target file. Since the second category file corresponding to the target storage granularity can be quickly determined among multiple second category files through the free file index table, the efficiency of the first target file can be improved.

[0100] Furthermore, combined with the above Figure 3 The embodiment of the present invention provides another file storage method to implement the above step S202, such as Figure 4 As shown, the steps include:

[0101] S401: Obtain a free storage space index table of a first target file.

[0102] In this step, the above-mentioned free storage space index table records the second identification information of the storage space in the free state in the storage space where the first target file is divided. The second identification information can be pre-established or updated in real time with operations such as adding and deleting. In one embodiment, the second identification information can be the file name of the storage space or the storage path of the storage space and other information.

[0103] Exemplarily, there are three first target files, namely files A, B and C, wherein file A has one free storage space a, file B has two free storage spaces b and c, and file C has two free storage spaces d, e and f. For file A, its free storage space index table records the second identification information of storage space a, for file B, its free storage space index table records the second identification information of storage spaces b and c, for file B, its free storage space index table records the second identification information of storage spaces b and c, and for file C, its free storage space index table records the second identification information of storage spaces d, e and f.

[0104] S402: Determine a storage space in an idle state as the idle storage space according to the second identification information recorded in the idle storage space index table.

[0105] In this step, a storage space in an idle state may be determined as the idle storage space according to the second identification information recorded in the idle storage space index table.

[0106] Exemplarily, for file A, if the second identification information of storage space a is recorded in its free storage space index table, then storage space a is used as free storage space; for file B, if the second identification information of storage spaces b and c is recorded in its free storage space index table, then storage spaces b and c are used as free storage space.

[0107] S403: Storing the file to be stored in the free storage space.

[0108] In this step, when there are multiple free storage spaces, the free storage space for storing the file to be stored can be determined from the multiple free storage spaces in the following manner, including:

[0109] According to a preset third determination rule, in the free storage space, a free storage space for storing the file to be stored is determined as the first target storage space.

[0110] The third determination rule may be determined based on factors such as demand or experience, and may be based on a preset third determination rule.

[0111] In one embodiment, the third determination rule may be to randomly determine a free storage space in the free storage space for storing the file to be stored.

[0112] Exemplarily, there are free storage spaces b and c, and one of the storage spaces b and c can be randomly determined as the first target storage space.

[0113] In the above-mentioned another file storage method provided by an embodiment of the present invention, a free storage space index table of the first target file can be obtained, wherein the free storage space index table records the second identification information of the storage space in the storage space divided by the first target file and which is in an idle state, and based on the second identification information recorded in the free storage space index table, the storage space in an idle state is determined as the free storage space, and the file to be stored is stored in the free storage space. Since the free storage space index table is used, the free storage space can be quickly determined in the second category of documents.

[0114] In another embodiment provided by the present invention, in combination with the above embodiment, the present invention implements the above file storage method, which may also include the following steps:

[0115] S404: Obtain identification information of the file to be stored as third identification information.

[0116] In this step, the identification information of the file to be stored may be the name of the file to be stored, or may be a hash code obtained after a hash operation is performed on the stored file.

[0117] S405: The first identification information of the first target file, the second identification information of the free storage space, and the third identification information are associated and written into a preset first-category file index table.

[0118] In this step, the first identification information of the first target file storing the file to be stored, the second identification information of the free storage space storing the file to be stored, and the low three identification information of the file to be stored can be associated and written into a preset first-category file index table, so that the first-category file index table records the storage information of each stored first-category file.

[0119] Based on the above embodiment of the present invention, in another embodiment of the present invention, a file deletion method is further provided to delete the first type of files stored in the second type of files, such as Figure 5 As shown, the method comprises the following steps:

[0120] S501: When a deletion operation for a first type of file to be deleted is received, a second type of file storing the first type of file to be deleted is determined as a second target file.

[0121] In this step, identification information of the first category of files to be deleted may be determined as fourth identification information, and the second category of files storing the first category of files to be deleted may be determined based on the fourth identification information.

[0122] Exemplarily, when a first-category file A is stored in a storage space e of a second-category file D, when a deletion operation is received for the first-category file A, the identification information of the first-category file A can be obtained. Those skilled in the art can understand that the identification information is the same as the identification information recorded when the first-category file A is stored.

[0123] Optionally, the first identification information and the second identification information associated with the fourth identification information may be searched in the first category file index table based on the fourth identification information.

[0124] Exemplarily, it can be seen from the above embodiments that when the first type file A is stored in the storage space e of the second type file D, the first type file index table records the first identification information of the second type file D stored in the first type file A, the second identification information of the storage space e stored in the first type file A, and the identification information of the first type file A. Therefore, when a delete operation for the first type file A is received, the first identification information of the second type file D and the second identification information of the storage space e can be found in the first type file index table based on the identification information of the first type file A.

[0125] Optionally, in each second category file, based on the found first identification information, a second category file storing the file to be deleted is determined as the second target file.

[0126] As in the above example, the first identification information of the second category file D can be used to determine that the first category file A is stored in the second category file D.

[0127] Optionally, based on the found second identification information, a storage space storing the first type of files to be deleted is determined in the second target file as the second target storage space.

[0128] As in the above example, the second identification information of the storage space e can be used to determine that the first type of file A is stored in the storage space e of the second type of file D, so that the storage space e can be determined as the second target storage space.

[0129] S502: Deleting the first type of files to be deleted from the second target file.

[0130] In this step, the first type of files to be deleted stored in the second target storage space may be deleted, and the second target storage space may be marked as being in an idle state.

[0131] As in the above example, after determining that the first category file A is stored in the storage space e of the second category file D, the first category file A in the storage space e can be deleted and the storage space e can be marked as idle so that the storage space e can store the first category file again.

[0132] In the above-mentioned file deletion method provided by an embodiment of the present invention, when a deletion operation for a first category of files to be deleted is received, a second category of files storing the first category of files to be deleted can be determined as a second target file, and the first category of files to be deleted can be deleted in the second target file, thereby realizing the deletion of the first category of files stored in the second category of files.

[0133] Based on the same inventive concept, according to the file storage method provided by the embodiment of the present invention, the embodiment of the present invention also provides a file storage device, such as Figure 6 As shown, the device comprises:

[0134] The file acquisition module 601 is used to acquire a first type of file to be stored as the file to be stored, and determine the data volume of the file to be stored, wherein the first type of file is a file whose data volume is not greater than a first preset threshold;

[0135] The storage granularity determination module 602 is used to determine, according to the data volume, a storage granularity that matches the data volume as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of files, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of files; wherein the second type of files are files whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold;

[0136] The file storage module 603 is used to store the files to be stored in the second type of files corresponding to the target storage granularity.

[0137] Furthermore, for each storage granularity, the storage granularity corresponds to a plurality of second-type files whose storage space is divided according to the storage granularity;

[0138] The file storage module 603 specifically determines a second-category file for storing the file to be stored among the multiple second-category files corresponding to the target storage granularity as a first target file, and stores the file to be stored in the first target file.

[0139] Furthermore, the file storage module 603 is specifically used to obtain a free file index table corresponding to the target storage granularity, wherein the free file index table is used to record the first identification information of the second category file corresponding to the target storage granularity and having a storage space in an idle state, and among multiple second category files, determine the second category file identified by the first identification information recorded in the free file index table as the first target file.

[0140] Furthermore, the file storage module 603 is also used to create a second type of file corresponding to the target storage granularity according to the target storage granularity if the record in the free file index table is empty, and write the first identification information of the second type of file into the free file index table.

[0141] Furthermore, the file storage module 603 is specifically used to obtain a free storage space index table of the first target file, wherein the free storage space index table records second identification information of the storage space in the storage space divided by the first target file and is in a free state, and based on the second identification information recorded in the free storage space index table, the storage space in a free state is determined as the free storage space, and the content to be stored is stored in the free storage space.

[0142] Furthermore, the device also includes:

[0143] The information writing module 604 is used to obtain the identification information of the file to be stored as the third identification information after the file storage module executes the storage of the file to be stored in the free storage space, and associates the first identification information of the first target file, the second identification information of the free storage space, and the third identification information and writes them into a preset first-category file index table.

[0144] Furthermore, the device also includes:

[0145] The file deletion module 605 is used for, when receiving a deletion operation for a first type of file to be deleted, determining a second type of file storing the first type of file to be deleted as a second target file, and deleting the first type of file to be deleted in the second target file.

[0146] The embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, it includes a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704.

[0147] Memory 703, used for storing computer programs;

[0148] The processor 701 is used to execute the program stored in the memory 703 to implement the following steps:

[0149] Acquire a first type of file to be stored as the file to be stored, and determine the data volume of the file to be stored, wherein the first type of file is a file whose data volume is not greater than a first preset threshold;

[0150] Determine a storage granularity matching the data amount according to the data amount as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of files, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of files; wherein the second type of files are files whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold;

[0151] The files to be stored are stored in a second type of files corresponding to the target storage granularity.

[0152] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0153] The communication interface is used for communication between the above electronic device and other devices.

[0154] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0155] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0156] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned file storage methods are implemented.

[0157] In another embodiment of the present invention, a computer program product including instructions is provided, which, when executed on a computer, enables the computer to execute any file storage method in the above embodiments.

[0158] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0159] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0160] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for devices, electronic devices, computer-readable storage media, and computer program products, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0161] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A file storage method, characterized in that: include: Acquire a first type of file to be stored as the file to be stored, and determine the data volume of the file to be stored, wherein the first type of file is a file whose data volume is not greater than a first preset threshold; Determine a storage granularity matching the data amount according to the data amount as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of files, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of files; wherein the second type of files are files whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold; Storing the file to be stored in a second type of file corresponding to the target storage granularity; Determining a storage granularity matching the data amount according to the data amount as a target storage granularity includes: Determine, from among a plurality of preset data volume ranges, a data volume range to which the data volume belongs as a target data volume range; wherein the plurality of data volume ranges do not overlap with each other and are adjacent; Based on the correspondence between the preset data volume range and the storage granularity, determine the storage granularity corresponding to the target data volume range among multiple storage granularities as the target storage granularity; wherein, in the correspondence, the maximum value of any data volume range is the storage granularity corresponding to the data volume range; For each storage granularity, the storage granularity corresponds to a plurality of second-type files whose storage space is divided according to the storage granularity; The storing the to-be-stored file in a second type of file corresponding to the target storage granularity includes: Determining, among the plurality of second-category files corresponding to the target storage granularity, a second-category file for storing the file to be stored as a first target file; Storing the file to be stored in the first target file; The second type of file determined to store the file to be stored, among the plurality of second type of files corresponding to the target storage granularity, as the first target file includes: Acquire a free file index table corresponding to the target storage granularity, wherein the free file index table is used to record first identification information of second-category files corresponding to the target storage granularity and having storage space in an idle state; Among the multiple second-category files, a second-category file identified by the first identification information recorded in the free file index table is determined as a first target file; the first target file is a file with the smallest data volume among the multiple second-category files.

2. The method according to claim 1, characterized in that After obtaining the free file index table corresponding to the target storage granularity, the method further includes: If the record in the free file index table is empty, a second type of file corresponding to the target storage granularity is created according to the target storage granularity, and the first identification information of the second type of file is written into the free file index table.

3. The method according to claim 1, characterized in that The step of storing the file to be stored in the first target file includes: Acquire a free storage space index table of the first target file, wherein the free storage space index table records second identification information of storage spaces in a free state in the storage spaces into which the first target file is divided; Determine, according to the second identification information recorded in the free storage space index table, a storage space in an idle state as the free storage space; The file to be stored is stored in the free storage space.

4. The method according to claim 3, characterized in that After storing the file to be stored in the free storage space, the method further includes: Obtaining identification information of the file to be stored as third identification information; The first identification information of the first target file, the second identification information of the free storage space, and the third identification information are associated and written into a preset first-category file index table.

5. The method according to claim 1, characterized in that The method further comprises: When a deletion operation for a first category of files to be deleted is received, determining a second category of files storing the first category of files to be deleted as a second target file; In the second target file, the first type of files to be deleted are deleted.

6. A file storage device, characterized in that: include: A file acquisition module, used to acquire a first type of file to be stored as the file to be stored, and determine the data volume of the file to be stored, wherein the first type of file is a file whose data volume is not greater than a first preset threshold; a storage granularity determination module, configured to determine, according to the data volume, a storage granularity matching the data volume as a target storage granularity, wherein the target storage granularity is used to divide the storage space of the second type of files, and the size of the target storage granularity represents the size of each storage space obtained by dividing the storage space of the second type of files; wherein the second type of files are files whose storage capacity is not less than a second preset threshold, and the first preset threshold is less than the second preset threshold; A file storage module, used for storing the file to be stored in a second type of file corresponding to the target storage granularity; The storage granularity determination module is specifically used to determine the data volume range to which the data volume belongs in a plurality of preset data volume ranges as the target data volume range; wherein the plurality of data volume ranges do not overlap with each other and are adjacent; Based on the correspondence between the preset data volume range and the storage granularity, the storage granularity corresponding to the target data volume range is determined among multiple storage granularities as the target storage granularity; wherein, in the correspondence, the maximum value of any data volume range is the storage granularity corresponding to the data volume range; For each storage granularity, the storage granularity corresponds to a plurality of second-type files whose storage space is divided according to the storage granularity; The file storage module specifically determines, among the plurality of second-category files corresponding to the target storage granularity, a second-category file for storing the file to be stored as a first target file, and stores the file to be stored in the first target file; The file storage module is specifically used to obtain a free file index table corresponding to the target storage granularity, wherein the free file index table is used to record the first identification information of a second-category file corresponding to the target storage granularity and having storage space in an idle state, and among the multiple second-category files, the second-category file identified by the first identification information recorded in the free file index table is determined as the first target file; the first target file is the file with the smallest amount of data among the multiple second-category files.

7. The device according to claim 6, characterized in that The file storage module is also used to create a second type of file corresponding to the target storage granularity according to the target storage granularity if the record in the free file index table is empty, and write the first identification information of the second type of file into the free file index table.

8. The device according to claim 6, characterized in that The file storage module is specifically used to obtain a free storage space index table of the first target file, wherein the free storage space index table records second identification information of the storage space in the storage space divided by the first target file and is in a free state, and based on the second identification information recorded in the free storage space index table, the storage space in a free state is determined as the free storage space, and the file to be stored is stored in the free storage space.

9. The device according to claim 8, characterized in that The device also includes: An information writing module is used to obtain identification information of the file to be stored as third identification information after the file storage module stores the file to be stored in the free storage space, and to write the first identification information of the first target file, the second identification information of the free storage space and the third identification information into a preset first-category file index table in an associated manner.

10. The device according to claim 6, characterized in that The device also includes: The file deletion module is used for, when receiving a deletion operation for a first type of file to be deleted, determining a second type of file storing the first type of file to be deleted as a second target file, and deleting the first type of file to be deleted in the second target file.

11. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-5 when executing a program stored in a memory.