A mass small file reading and writing method and system, an electronic device, and a storage medium
By merging small files into large files and storing them in a cloud storage system using key-value pairs, the problem of low disk space utilization in the storage of massive amounts of small files is solved, achieving high-efficiency read and write performance.
Patent Information
- Application Number
- CN202211035779.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-26
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2042-08-26
AI Technical Summary
Existing technologies cannot effectively distinguish between large and small files in the storage of massive amounts of small files, resulting in low disk space utilization and low read/write performance.
By merging small files into large files and storing them in a cloud storage system, and setting key-value pairs to cache in an external storage system, fast location and read/write of small files can be achieved.
It improves the read and write performance of massive numbers of small files, and enhances disk space utilization and read/write performance.
Smart Images

Figure CN115481086B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of distributed storage technology, and in particular to a method, system, electronic device, and storage medium for reading massive amounts of small files. Background Technology
[0002] With the explosive growth of data volume, storage needs are receiving increasing attention, and existing storage technologies are mainly designed for storing large files.
[0003] In the process of researching and practicing existing technologies, the inventors of this application have discovered that in the storage of massive small files, the use of distributed storage in existing technologies has the disadvantages of not being able to effectively distinguish between large and small files, having low adaptability, low disk space utilization, and thus resulting in low performance efficiency for reading and writing massive small files. Summary of the Invention
[0004] The main technical problem addressed by this application is to provide a method, system, electronic device, and storage medium for reading massive amounts of small files. This method can store small files in a manner similar to large files, and then locate and read the small files using key-value pairs, thereby enabling the reading and writing of massive amounts of small files and improving the performance and efficiency of small file reading and writing.
[0005] To address the aforementioned technical problems, this application provides a method for reading massive amounts of small files. The method includes: acquiring small files; determining a list of files to be merged based on the small files; caching the data information of the small files in an aggregate file according to the list of files to be merged; wherein the aggregate file is a cloud storage file created in the form of a large file in a cloud storage system; setting key-value pairs based on the aggregate file and caching the key-value pairs in an external storage system; and reading and downloading the small files based on the key-value pairs.
[0006] In one embodiment of this application, caching the data information of the small files to the aggregate file according to the list of files to be merged includes: retrieving the list of files to be merged, caching the retrieved small files to a first cache container; creating an aggregate file in the cloud storage system in the form of a large file; and caching the data information of the small files in the first cache container to the aggregate file.
[0007] In one embodiment of this application, caching the data information of the small file in the first cache container to the aggregate file includes: if the data information of the small file in the first cache container is successfully written to the aggregate file, then the filename corresponding to the small file is cached in the second cache container; if the data information of the small file in the first cache container is not written to the aggregate file, then the filename corresponding to the small file is cached in the third cache container.
[0008] In one embodiment of this application, after caching the aggregated files, the method further includes: deleting the list of files to be merged and their corresponding metadata information according to the cache information of the second cache container.
[0009] In one embodiment of this application, after caching the data information of the small files in the first cache container to the aggregate file, the method further includes: closing the aggregate file when the size of the aggregate file reaches a preset threshold; creating a new aggregate file in the cloud storage system in the form of a large file and caching the remaining data information of the small files in the new aggregate file.
[0010] In one embodiment of this application, setting key-value pairs based on the aggregated file and caching the key-value pairs to an external storage system includes: setting the storage directory of the aggregated file as the key value and setting the small file index information in the aggregated file as the value value; and caching the key value and the value value to the external storage system.
[0011] In one embodiment of this application, reading and downloading the small file based on the key-value pair includes: responding to a user's search request, searching a database to obtain a corresponding database file list and searching an external storage system to obtain a corresponding small file list based on the key value; integrating the database file list and the small file list, removing aggregated files, and returning the results to the user; and the user reading the data information of the small file from the cloud storage system based on the value.
[0012] In one embodiment of this application, when it is necessary to delete small cached files, the method further includes: obtaining the proportion of deleted files in the aggregate file; if the proportion reaches a proportion threshold, regenerating a new aggregate file for the small files that have not been deleted in the aggregate file, and deleting the original aggregate file.
[0013] In one embodiment of this application, the step of regenerating a new aggregate file for the small files that have not been deleted in the aggregate file and deleting the original aggregate file when the percentage reaches a percentage threshold includes: obtaining the percentage of deleted files accumulated; if the percentage reaches a percentage threshold, retrieving the small files that have not been deleted in the original aggregate file from the external storage system and generating an aggregate sub-file accordingly; and deleting the original aggregate file.
[0014] In one embodiment of this application, obtaining a small file includes: caching the written file as a large file in a cloud storage system; obtaining the size of the written file; and if the written file is smaller than a preset file size threshold, it is recorded as a small file.
[0015] In one embodiment of this application, determining the list of files to be merged based on the small files includes: obtaining the filenames of the small files; and determining the list of files to be merged based on the filenames of the small files.
[0016] To address the aforementioned technical problems, another technical solution of this application is: providing a massive small file read / write system, the system comprising: an acquisition module for acquiring small files; a determination module for determining a list of files to be merged based on the small files; a first caching module for caching the data information of the small files to an aggregate file according to the list of files to be merged; wherein the aggregate file is a cloud storage file created in the form of a large file in a cloud storage system; a second caching module for setting key-value pairs based on the aggregate file and caching the key-value pairs to an external storage system; and a reading module for reading and downloading the small files based on the key-value pairs.
[0017] To solve the above-mentioned technical problems, another technical solution of this application is to provide an electronic device, the electronic device including: a memory and a processor coupled to the memory, the memory storing at least one computer program, and when the at least one computer program is loaded and executed by the processor, it is used to implement the above-mentioned method for reading and writing massive small files.
[0018] To address the aforementioned technical problems, another technical solution of this application is to provide a computer-readable storage medium storing at least one program, which, when loaded and executed by a processor, is used to implement the aforementioned method for reading and writing large amounts of small files.
[0019] Unlike existing technologies, this application provides a method for reading and writing massive amounts of small files, including: acquiring small files; determining a list of files to be merged based on the small files; caching the data information of the small files to an aggregate file according to the list of files to be merged; wherein the aggregate file is a cloud storage file created in the form of a large file in a cloud storage system; setting key-value pairs based on the aggregate file and caching the key-value pairs to an external storage system; and reading and downloading the small files based on the key-value pairs. In other words, this application automatically acquires small files and uses them to determine a list of files to be merged, then stores the data information of the small files in the form of large files in a cloud storage system based on the list of files to be merged, sets key-value pairs based on the large file format of the stored file and stores the key-value pairs in external storage, and reads and downloads the small files using the key-value pairs, thereby achieving rapid location and reading / writing of massive amounts of small files and improving the performance efficiency of small file reading and writing. Attached Figure Description
[0020] Figure 1 This is a flowchart illustrating an embodiment of the method for reading and writing massive small files according to the present invention;
[0021] Figure 2This is a flowchart illustrating an embodiment of step S1 of the present invention;
[0022] Figure 3 This is a flowchart illustrating an embodiment of step S2 of the present invention;
[0023] Figure 4 This is a flowchart illustrating an embodiment of step S3 of the present invention;
[0024] Figure 5 This is a flowchart illustrating an embodiment of step S33 of the present invention;
[0025] Figure 6 This is a flowchart illustrating a subsequent embodiment of step S3 of the present invention;
[0026] Figure 7 This is a flowchart illustrating an embodiment of step S4 of the present invention;
[0027] Figure 8 This is a flowchart illustrating an embodiment of step S5 of the present invention;
[0028] Figure 9 This is a flowchart illustrating an embodiment of the present invention for deleting small cache files;
[0029] Figure 10 This is a flowchart illustrating an embodiment of step A2 of the present invention;
[0030] Figure 11 This is a schematic diagram of the structure of an embodiment of the massive small file reading and writing system of the present invention;
[0031] Figure 12 This is a schematic diagram of the structure of an embodiment of the electronic device of the present invention;
[0032] Figure 13 This is a schematic diagram of the structure of an embodiment of the computer-readable storage medium of the present invention. Detailed Implementation
[0033] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be particularly noted that the following embodiments are for illustrative purposes only and do not limit the scope of the invention. Similarly, the following embodiments are only some, not all, embodiments of the present invention, and all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0034] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0035] Traditional file storage methods, especially for storing massive amounts of small files, suffer from several drawbacks. Some rely on replication for data categorization, resulting in low disk space utilization and a lack of versatility. Others have excessively long storage structures, struggle with the large volume of cloud data, and fail to clearly differentiate between large and small files. Still others require clients to generate and send related information, leading to a poor user experience. Therefore, using replication, Redis, or tiered storage methods, particularly for Fuse-based distributed cloud storage systems, yields unsatisfactory read / write performance for massive amounts of small files, resulting in low efficiency.
[0036] The applicant discovered in their research that, given the low performance efficiency of reading and writing massive amounts of small files in existing technologies, especially when dealing with massive amounts of small files experiencing explosive data growth, they can automatically distinguish between large and small files. Small files with similar lifecycles can be asynchronously appended to larger files for storage. Furthermore, by including file index information in filenames and providing an additional key-value system to carry the cloud data of small files, the applicant can achieve efficient reading and writing of massive amounts of small files. This effectively improves the performance and efficiency of reading and writing massive amounts of small files in distributed storage systems, particularly addressing the problem of low performance efficiency in managing massive amounts of small files in Fuse-based distributed cloud storage systems.
[0037] Therefore, a method for reading and writing massive small files is proposed and applied to a Fuse-based distributed cloud storage system. The method involves: acquiring small files; determining a list of files to be merged based on the small files; caching the data information of the small files into an aggregate file based on the list of files to be merged; wherein the aggregate file is a cloud storage file created in the cloud storage system in the form of a large file; setting key-value pairs based on the aggregate file and caching the key-value pairs in an external storage system; and reading and downloading the small files based on the key-value pairs.
[0038] The Fuse-based distributed cloud storage system includes a client, a user-space file system (Fuse), a distributed cloud storage system, a database, and a distributed key-value (KV) storage system. The client sends a file storage request to the user-space file system and writes the file. The user-space file system receives and stores the file data, and then stores the written file as a large file in the distributed cloud storage system. When a file is closed, the file size is retrieved, and the metadata of the corresponding smaller files is recorded in the database. A list of files to be merged is maintained in the database, recording the filenames of these smaller files. The database is periodically searched for files to be merged. The system retrieves small files to be merged from a list, asynchronously appends these small files to an aggregate file created as a large file, and records the cloud data of the aggregate file in the database. After the small files are successfully written to the aggregate file, the storage directory of the aggregate file is used as the key, and the small file, its starting offset in the aggregate file, and its size are concatenated into a string and recorded as the corresponding value in the distributed key-value storage system. The distributed key-value storage system then manages the cloud data of the small files, and performs file retrieval, download, or deletion operations by comparing the list of small files corresponding to the small files in the distributed key-value storage system with the list of small files corresponding to the small files in the database.
[0039] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the method for reading and writing massive small files according to the present invention; it should be noted that if substantially the same result is obtained, the method of the present invention is not based on... Figure 1 The process sequence shown is limited to the following: Figure 1 As shown, the method includes the following steps:
[0040] S1. Obtain the small file;
[0041] Small files typically refer to files smaller than 1MB, while files in the millions or more can be considered massive. Most of these files are unstructured data, including videos, images, and documents, and with the rapid development of technology, they have reached hundreds of billions or even trillions in size.
[0042] See Figure 2 , Figure 2 This is a flowchart illustrating an embodiment of step S1 of the present invention. Step S1 includes:
[0043] S11. Cache the written file to the cloud storage system as a large file;
[0044] The file to be written can include both large and small files. Here, the distinction between large and small files is not made. Therefore, all files that need to be stored are collectively referred to as files to be written.
[0045] Specifically, all files are treated as large files, and all types of files that need to be stored are cached in the cloud storage system as large files.
[0046] In some embodiments, when the file size cannot be determined at the time of writing, each file that needs to be stored is uniformly treated as a large file, and these large files are then cached in the cloud storage system; for example, these large files are stored in a distributed cloud storage system based on the Fuse framework, where Fuse is a user-space file system.
[0047] In some embodiments, after a file is stored in a cloud storage system, the file's cloud data is recorded in a database (DataBase), and the metadata includes file-related information such as: Bucket name, directory name, file name, file creation time, and file size.
[0048] S12, Get the size of the file to be written;
[0049] The size of the file to be written cannot be obtained before writing.
[0050] Specifically, after all files are stored as large files in the cloud storage system, the size of the written file is obtained when the file is closed.
[0051] In some embodiments, such as those based on the Fuse framework combined with a distributed cloud storage system, the size of a file cannot be determined before or during writing. Therefore, the file size is set to be obtained when the file is closed.
[0052] In some embodiments, the size of the file being written can be obtained after the file is written or while the file is being written.
[0053] S13. If the file size written is smaller than the preset file size threshold, it is recorded as a small file.
[0054] The preset file size threshold is used to distinguish between files of different sizes and can be set according to actual needs.
[0055] Specifically, a file size threshold is preset. After obtaining the size of the file to be written, it is compared with the preset file size threshold. Files written that are smaller than the preset file size threshold are recorded as small files.
[0056] In some embodiments, the files to be written can be categorized into large and small files. Large files are those with a size greater than or equal to 1MB, regardless of the file format. Small files are those less than 1MB. Small files can be unstructured data, which is data that is not structured according to a predefined data model or organized in a predefined way. It can be generated by humans or machines and has an internal structure, such as documents, books, images, audio, video, files, email messages, web pages, etc. It can also be structured data, which is data that is structured according to a predefined model or organized in a predefined way, and is usually stored in a relational database management system.
[0057] S2. Determine the list of files to be merged based on small files;
[0058] The list of files to be merged is a data table maintained by the database (DataBase) to record relevant data about small files.
[0059] See Figure 3 , Figure 3 This is a flowchart illustrating an embodiment of step S2 of the present invention. Step S2 includes:
[0060] S21. Obtain the filename of the small file;
[0061] Each file has a corresponding filename; large files have a corresponding name, and small files have a corresponding name.
[0062] Specifically, after distinguishing between large and small files, the relevant information of the small files is extracted, and then the corresponding filenames of the small files are obtained.
[0063] S22. Determine the list of files to be merged based on the filenames of smaller filenames.
[0064] The list of files to be merged can be used to record relevant data for small files; here, it is used to record the filenames of the small files.
[0065] Specifically, after extracting the relevant information of the small files, the filenames of the small files are obtained and recorded in the list of files to be merged to determine the size of the data in the list of files to be merged, and thus determine the list of files to be merged.
[0066] In some embodiments, the list of files to be merged can also be determined by other information that can represent small files, such as file number, file extension, etc. For example, after extracting the relevant information of small files, the file number corresponding to the small files can be obtained, and the file number corresponding to these small files can be recorded in the list of files to be merged to determine the data size of the list of files to be merged, and thus determine the list of files to be merged.
[0067] S3. Cache the data information of small files into the aggregate file based on the list of files to be merged;
[0068] Among them, the aggregated file is a cloud storage file created in the cloud storage system in the form of a large file, used to store the data information of the corresponding files in the list of files to be merged.
[0069] See Figure 4 , Figure 4 This is a flowchart illustrating an embodiment of step S3 of the present invention. Step S3 includes:
[0070] S31. Retrieve the list of files to be merged, and cache the retrieved small files in the first cache container;
[0071] The first cache container is a local cache container used to cache files to be aggregated; that is, the first container is used to cache small files waiting to be aggregated.
[0072] Specifically, the system periodically retrieves the list of files to be merged maintained in the database, obtains all the small files to be merged based on the relevant information recorded in the list, and saves all the small files to be merged in the local cache container for files to be merged, that is, in the first cache container.
[0073] In some embodiments, a scheduled task needs to be set up to periodically check the list of files to be merged maintained in the database.
[0074] S32. Create an aggregate file in the cloud storage system as a large file;
[0075] "Large file format" refers to the format of a large file and does not specifically refer to a certain file type.
[0076] Specifically, in the cloud storage system, a new cloud storage file is created in the form of a large file and named the aggregate file.
[0077] In some embodiments, the large file format does not limit the upper limit of the file size, but it does not exceed the size of the database, that is, the aggregated file is a file larger than 1MB and smaller than the size of the database.
[0078] S33. Cache the data information of small files in the first cache container to the aggregate file.
[0079] The data information of the small files in the first cache container is the same as the data information of the small files in the file container to be merged in the database (DataBase).
[0080] Specifically, based on the information that can represent small files cached in the file container to be merged, the cloud data information of the files to be merged is first obtained from the cloud storage system and stored locally, that is, stored in the database. Then, the relevant data of the small files is read and written into the aggregate file. At the same time, the information describing the aggregate file, such as the current offset and total length, is recorded and updated locally.
[0081] In some embodiments, cloud data information of the files to be merged can be obtained from the cloud storage system and stored locally, i.e., in a database, based on the filename or file number of the small files corresponding to the small files cached in the file container to be merged. Then, the corresponding small file data content is read from the cloud storage system and asynchronously appended to the aggregate file of the cloud storage system. Information such as the current offset and total length of the aggregate file is recorded and updated in the database.
[0082] See Figure 5 , Figure 5 This is a flowchart illustrating an embodiment of step S33 of the present invention. Step S33 includes:
[0083] S331. If the data information of the small file in the first cache container is successfully written to the aggregate file, then the small file name corresponding to the small file is cached in the second cache container.
[0084] The second cache container is a local cache container used to cache the aggregated files; that is, the second cache container is used to cache small files that have already been aggregated.
[0085] Specifically, if the data information of small files in the local cache container used to cache files to be aggregated is successfully written into the aggregate file of the cloud storage system, then the information representing the small files after the aggregation is completed is cached in the local cache container used to cache the files after the aggregation is completed.
[0086] In some embodiments, in a local cache container used to cache aggregated files, the cached aggregated information that represents small files can be content that represents small files, such as small file names or small file numbers.
[0087] S332. If the data information of the small file in the first cache container is not written to the aggregate file, then the small file name corresponding to the small file is cached in the third cache container.
[0088] The third cache container is a local cache container used to cache files that failed to aggregate; that is, the third cache container is used to cache small files that failed to aggregate.
[0089] Specifically, if the data information of small files in the local cache container used to cache files to be aggregated is not successfully written to the aggregated file of the cloud storage system, then the information of the small files that failed to aggregate will be cached in the local storage container used to cache files that failed to aggregate.
[0090] In some embodiments, in a local cache container used to cache files that failed to aggregate, the cached information representing small files that failed to aggregate can be content that represents small files, such as small file names or small file numbers.
[0091] In some embodiments, after caching the aggregated files, the method further includes: deleting the list of files to be merged and their corresponding metadata information according to the cache information of the second cache container, thereby freeing up the corresponding space.
[0092] See Figure 6 , Figure 6 This is a flowchart illustrating an embodiment following step S33 of the present invention, including:
[0093] S34. When the size of the aggregated file reaches a preset threshold, the aggregated file is closed;
[0094] The preset threshold is used to limit the size of the aggregate file. Once the size of the aggregate file reaches the preset threshold, the aggregate file will no longer be used to store information.
[0095] Specifically, a preset threshold is set for the aggregate file. When the size of the aggregate file reaches the preset threshold, the aggregate file is closed and no new information is stored in the aggregate file.
[0096] In some embodiments, if the aggregate file still has some remaining space, and the size of the file to be stored is greater than the remaining space of the aggregate file, it also indicates that the size of the aggregate file has reached a preset threshold, and the aggregate file can be closed.
[0097] S35. Create a new aggregate file in the cloud storage system as a large file and use the new aggregate file to cache the data information of the remaining small files.
[0098] Among them, newly created aggregate files are cloud storage files created in the cloud storage system as large files.
[0099] Specifically, after the original aggregate file reaches a preset threshold and is closed, a new cloud storage file is created in the cloud storage system as a new aggregate file in the form of a large file, and the data information of the remaining small files is cached through the new aggregate file.
[0100] In some embodiments, there may be one or more new aggregate files, as long as the data storage requirements of the successfully aggregated small files are met.
[0101] S4. Set key-value pairs based on the aggregated file and cache the key-value pairs to the external storage system;
[0102] Here, key-value pairs are corresponding key-value pairs, and the corresponding key-value content can be obtained through one of the key-value pairs; the external storage system can be a separate storage subsystem, which has connections with the cloud storage system and the database.
[0103] In some embodiments, cloud data for small files can be managed in an external storage system.
[0104] See Figure 7 , Figure 7 This is a flowchart illustrating an embodiment of step S4 of the present invention. Step S4 includes:
[0105] S41. Set the storage directory of the aggregate file as the Key value, and set the small file index information in the aggregate file as the Value value;
[0106] After the aggregated file stores the successfully aggregated small files, a storage directory for the aggregated file will be generated based on the information that represents the small files, and corresponding small file index information will be generated based on the successfully aggregated small files.
[0107] Specifically, after all successfully aggregated small files are stored in the aggregate file, information representing the small files is obtained to generate the storage directory of the aggregate file, and this storage directory is used as the key value; and the small file index information generated based on the successfully aggregated small files is used as the value value.
[0108] In some embodiments, the storage directory of the aggregate file may be a filename or file number that represents the small files, or other information that represents the small files; the small file index information may be a string formed by concatenating the starting offset between small files in the aggregate file and the size of the small files, or a string formed by concatenating the small file number and the size of the small files, or a string formed by concatenating the starting position of the small files and the size of the small files, etc., which are related information that can represent the small file index.
[0109] S42. Cache the Key and Value values in the external storage system.
[0110] Specifically, the key and value are recorded in the external storage system.
[0111] In some embodiments, the external storage system may be a standalone distributed key-value storage system or other storage modules that can perform simple storage functions.
[0112] S5. Read and download small files based on key-value pairs.
[0113] The actual content (Value) of the data can be obtained by using the unique key value of each data address in the key-value pair. Therefore, small files can be read and downloaded using key-value pairs.
[0114] See Figure 8 , Figure 8 This is a flowchart illustrating an embodiment of step S5 of the present invention. Step S5 includes:
[0115] S51. In response to the user's search request, retrieve the corresponding database file list from the database and retrieve the corresponding small file list from the external storage system based on the Key value;
[0116] The database file list is a list of files stored in the database (DataBase), and the small file list is a list of corresponding small files in the external storage system.
[0117] Specifically, when a file retrieval is required, the system responds to the user's retrieval request by retrieving the database (DataBase) based on the retrieval criteria, and retrieves and caches the database file list under the specified directory; then, it retrieves the external storage system based on the Key value representing the aggregated file storage directory to obtain the list of small files under the same directory.
[0118] In some embodiments, retrieving a list of files in a specified directory from a database may include regular large files, aggregated files in the form of large files, or both regular large files and aggregated files in the form of large files.
[0119] In some embodiments, external storage systems can be retrieved using fuzzy matching; if necessary, they can also be retrieved using exact matching.
[0120] S52. After merging the database file list and the small file list and removing the aggregated file, return the results to the user.
[0121] The database file list contains regular large files and aggregate files, while the small file list includes small files that have already been stored in the aggregate files. Therefore, after merging the database file list and the small file list, the aggregate files are duplicates and need to be removed. Finally, a list of files without duplicate data is returned to the user.
[0122] Specifically, the system will integrate the list of files in the specified directory obtained from the database and the list of small files in the same directory obtained from the external storage system. After deleting duplicate aggregated files, the system will return a list of files without duplicate data to the user.
[0123] S53. Users read data information of small files from the cloud storage system based on the value.
[0124] The Value contains the index information of the small file in the aggregate file. Therefore, the small file name can be parsed using this index information to access the cloud storage system and read the relevant data.
[0125] Specifically, based on the aggregated file index information corresponding to the Value, the filename of the small file is parsed out, and the cloud storage system is accessed according to the small filename to read and download the data information corresponding to the small filename. This enables fast location of small files and improves the reading performance of small files.
[0126] In some embodiments, the small file name can be a Value recorded by the plug-in system, which contains the index information of the small file in the aggregate file, such as the starting offset, file size and other information related to the small file.
[0127] See Figure 9 , Figure 9 This is a flowchart illustrating the process of deleting small cache files in this invention, including:
[0128] A1. Obtain the percentage of deleted files in the aggregated file;
[0129] The deletion of small files mainly involves deleting the corresponding small file metadata in the external storage system.
[0130] Specifically: When a client requests the deletion of a small file, only the metadata record of the small file in the external storage system is deleted. At the same time, the detailed information of the aggregate file to which the requested small file belongs is maintained; for example, the aggregate file to which the requested small file belongs is designated as aggregate file 1, and the small file to be deleted is designated as small file 1.
[0131] Record or update the percentage of invalid content in the aggregate file. If the small file to be deleted is the first small file to be deleted in the aggregate file, calculate and record the ratio of the small file size to the aggregate file size. If the small file to be deleted is not the first small file to be deleted in the aggregate file, add the calculated percentage to the previously recorded percentage and then save the record. For example, if small file 1 is the first small file to be deleted in aggregate file 1, calculate and record the ratio of small file 1 to aggregate file 1 size. If small file 1 is not the first small file to be deleted in aggregate file 1, add the ratio of small file 1 size to aggregate file 1 size to the previously recorded percentage and then save the record.
[0132] In some embodiments, when requesting the deletion of a small file, only the metadata record of the small file in the distributed key-value system is deleted.
[0133] A2. If the percentage reaches the percentage threshold, regenerate a new aggregate file for the small files that have not been deleted in the aggregate file, and delete the original aggregate file.
[0134] The percentage refers to the proportion of small files in the aggregate file, specifically the proportion of small files that are requested to be deleted in the aggregate file. The percentage threshold is used to manage the size of the aggregate file. If a large number of files are deleted from the aggregate file, the size of the original aggregate file needs to be reduced to free up space and alleviate the serious problem of space fragmentation.
[0135] Specifically, it is determined whether the percentage of deleted files in aggregate file 1 has reached a threshold. If it has, the external storage system is detected to obtain all currently undeleted small files in aggregate file 1. The corresponding small file names are parsed to obtain the starting offset and length of the undeleted small files in aggregate file 1. The detailed information of the small files is stored in the database according to the starting offset size. Aggregate file 2 is regenerated based on the undeleted small files. The detailed information of the undeleted small files is transferred to aggregate file 2, and the original aggregate file is deleted.
[0136] See Figure 10 , Figure 10 This is a flowchart illustrating an embodiment of step A2 of the present invention. Step A2 includes:
[0137] A21. Obtain the cumulative percentage of deleted files;
[0138] The deleted files are the small files that were deleted from the aggregate file.
[0139] Specifically, obtain the size of the deleted small files in the aggregate file and calculate the proportion of the deleted small file size in the aggregate file.
[0140] In some embodiments, deleting a file can be deleting a small file or deleting multiple small files, so the goal is to obtain the cumulative percentage of deleted files.
[0141] A22. If the percentage reaches the percentage threshold, retrieve the small files that were not deleted from the original aggregate file from the external storage system, and use them to generate aggregate sub-files;
[0142] Specifically, if the proportion of deleted files in aggregate file 1 reaches a threshold, in order to free up space, the external storage system is searched to obtain all the small files that have not been deleted in aggregate file 1. The corresponding small file name is parsed to obtain the starting offset and file length in the aggregate file. The small file details are stored in the database according to the starting offset size of the small files. Then, the corresponding aggregate file 2 is generated based on the small files that have not been deleted, and the small file data is transferred to aggregate file 2 according to the small file details.
[0143] A23. Delete the original aggregate file.
[0144] Among them, the deleted original aggregation files were those that had already undergone data transfer.
[0145] Specifically, the aggregate file 1, which has already undergone data transfer, has overlapping data with the newly generated aggregate file 2. Therefore, the aggregate file 1, which has already undergone data transfer, is deleted to release space fragments and free up corresponding space.
[0146] In some embodiments, after each re-aggregation of small files in aggregate file 1 is completed, the cloud data information of the small file in the external storage system is modified, that is: the Key value is modified to the storage directory of aggregate file 2, and the corresponding Value value is modified to the index information of the small file in aggregate file 2.
[0147] In some embodiments, the small file index information corresponding to the modified Value can be a string formed by concatenating the starting offset between small files in the aggregate file and the size of the small file, or a string formed by concatenating the small file number and the size of the small file, or a string formed by concatenating the starting position of the small file and the size of the small file, etc., which can represent relevant information of the small file index.
[0148] Unlike existing technologies, this embodiment involves: acquiring small files; determining a list of files to be merged based on the small files; caching the data information of the small files to an aggregate file according to the list of files to be merged; wherein the aggregate file is a cloud storage file created in the cloud storage system as a large file; setting key-value pairs based on the aggregate file and caching the key-value pairs in an external storage system; and reading and downloading the small files based on the key-value pairs. In other words, this application, by acquiring small files, storing them as large files, setting corresponding key-value pairs in the external storage system, and performing read and write operations on the small files based on the key-value pairs, enables fast read and write operations on massive numbers of small files, improving the efficiency of reading and writing massive numbers of small files.
[0149] Please see Figure 11 , Figure 11This is a schematic diagram of an embodiment of the massive small file read / write system of the present invention. The system can execute the steps of the above-described massive small file read / write method. For related details, please refer to the detailed description in the above method, which will not be repeated here.
[0150] The massive small file read / write system 200 includes: an acquisition module 210, a determination module 220, a first cache module 230, a second cache module 240, and a reading module 250. The acquisition module 210 acquires small files; the determination module 220 determines a list of files to be merged based on the small files; the first cache module 230 caches the data information of the small files into an aggregate file based on the list of files to be merged; the aggregate file is a cloud storage file created in the cloud storage system as a large file; the second cache module 240 sets key-value pairs based on the aggregate file and caches the key-value pairs in an external storage system; and the reading module 250 reads and downloads the small files based on the key-value pairs.
[0151] Please see Figure 12 , Figure 12 This is a schematic diagram of an embodiment of the electronic device of the present invention. The electronic device can execute the steps in the above-described method for reading and writing massive amounts of small files. The electronic device 300 includes: a memory 310 and a processor 320 coupled to the memory. The memory 310 stores at least one computer program. When the at least one computer program is loaded and executed by the processor, it is used to implement the above-described method for reading and writing massive amounts of small files.
[0152] Please see Figure 13 , Figure 13 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention. The computer-readable storage medium 400 stores at least one program 410, which, when loaded and executed by a processor, is used to implement the above-described method for reading and writing massive amounts of small files.
[0153] The above solution aggregates small files into large files, enabling automatic differentiation between large and small files and adapting small file storage to existing cloud storage systems that prioritize large file storage. Based on the corresponding key-value pair settings, it greatly reduces the amount of cloud data, alleviates database pressure, and can be well applied to storage needs of hundreds of billions or even trillions of files, meeting corresponding business storage requirements and improving the read and write performance of massive small files.
[0154] In the several embodiments provided by this invention, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection of apparatuses or units, and may be electrical, mechanical, or other forms.
[0155] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0156] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0157] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0158] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for reading and writing massive amounts of small files, characterized in that, The method is applied to a Fuse-based distributed cloud storage system, wherein the Fuse-based distributed cloud storage system includes at least a distributed cloud storage system and an external storage system; the method includes: Get small files; Based on the small files, determine the list of files to be merged; The data information of the small files is cached into an aggregate file according to the list of files to be merged; wherein, the list of files to be merged is retrieved, and the retrieved small files are cached in a first cache container; an aggregate file is created in the cloud storage system in the form of a large file; the data information of the small files in the first cache container is cached into the aggregate file; if the data information of the small file in the first cache container is successfully written into the aggregate file, the corresponding small file name is cached in a second cache container; if the data information of the small file in the first cache container is not written into the aggregate file, the corresponding small file name is cached in a third cache container; the aggregate file is a cloud storage file created in the cloud storage system in the form of a large file. Key-value pairs are set based on the aggregated file, and the key-value pairs are cached in the external storage system; The small file is read and downloaded based on the key-value pairs; Specifically, when a client requests the deletion of a small file, only the metadata record of the small file in the external storage system is deleted; simultaneously, the detailed information of the aggregate file to which the requested small file belongs is maintained; the percentage of deleted small files in the aggregate file is recorded or updated; if the percentage reaches a threshold, the external storage system is detected to obtain all currently undeleted small files in the original aggregate file, and the corresponding small file names are parsed to obtain the starting offset and length of the undeleted small files in the original aggregate file; the detailed information of the small files is stored in the database in order of their starting offsets; the aggregate file is regenerated based on the undeleted small files, and the original aggregate file is deleted; after regenerating the aggregate file, the cloud data information of the undeleted small files in the external storage system is modified, with the Key value modified to the storage directory of the regenerated aggregate file, and the Value value modified to the index information of the small files in the regenerated aggregate file.
2. The method according to claim 1, characterized in that, After caching the aggregated files, the process also includes deleting the list of files to be merged and their corresponding metadata information based on the cache information of the second cache container.
3. The method according to claim 1, characterized in that, After caching the data information of the small files in the first cache container to the aggregate file, the method further includes: When the size of the aggregated file reaches a preset threshold, the aggregated file is closed. In the cloud storage system, a new aggregate file is created in the form of a large file, and the data information of the remaining small files is cached in the newly created aggregate file.
4. The method according to claim 1, characterized in that, The step of setting key-value pairs based on the aggregated file and caching the key-value pairs to the external storage system includes: Set the storage directory of the aggregate file as the key value, and set the small file index information in the aggregate file as the value value; The Key and Value values are cached in the external storage system.
5. The method according to claim 4, characterized in that, The process of reading and downloading the small file based on the key-value pairs includes: In response to a user's search request, the database is searched to obtain the corresponding list of database files, and the external storage system is searched based on the Key value to obtain the corresponding list of small files; The database file list and the small file list are combined, and the aggregated file is removed before being returned to the user. Users read data information of small files from the cloud storage system based on the Value.
6. The method according to claim 1, characterized in that, The acquisition of small files includes: The written files will be cached in the cloud storage system as large files; Obtain the size of the file to be written; If the file being written is smaller than a preset file size threshold, it is recorded as a small file.
7. The method according to claim 1, characterized in that, The step of determining the list of files to be merged based on the small files includes: Get the filename of the small file; The list of files to be merged is determined based on the filenames.
8. A system for reading and writing massive amounts of small files, characterized in that, The system is a Fuse-based distributed cloud storage system, which includes at least a distributed cloud storage system and an external storage system. The system comprises: The acquisition module is used to acquire small files; The determination module determines a list of files to be merged based on the small files; The first caching module is used to cache the data information of the small files to the aggregate file according to the list of files to be merged; wherein, the list of files to be merged is retrieved, and the retrieved small files are cached in a first cache container; an aggregate file is created in the cloud storage system in the form of a large file; the data information of the small files in the first cache container is cached in the aggregate file; if the data information of the small file in the first cache container is successfully written to the aggregate file, the corresponding small file name is cached in a second cache container; if the data information of the small file in the first cache container is not written to the aggregate file, the corresponding small file name is cached in a third cache container; the aggregate file is a cloud storage file created in the cloud storage system in the form of a large file; The second caching module sets key-value pairs based on the aggregated file and caches the key-value pairs to the external storage system; The reading module reads and downloads the small file based on the key-value pairs; The first caching module is further configured to: when a client requests the deletion of a small file, only delete the metadata record of the small file in the external storage system; simultaneously, maintain the detailed information of the aggregate file to which the requested small file belongs; record or update the percentage of deleted small files in the aggregate file; if the percentage reaches a threshold, detect the external storage system to obtain all currently undeleted small files in the original aggregate file, parse the corresponding small file names to obtain the starting offset and length of the undeleted small files in the original aggregate file, and save the detailed information of the small files in the database according to the starting offset size order; regenerate the aggregate file based on the undeleted small files and delete the original aggregate file; and after regenerating the aggregate file, modify the cloud data information of the undeleted small files in the external storage system, modifying the Key value to the storage directory of the regenerated aggregate file and the Value value to the index information of the small files in the regenerated aggregate file.
9. An electronic device, characterized in that, The electronic device includes: A memory and a processor coupled to the memory, the memory storing at least one computer program, which, when loaded and executed by the processor, is used to implement the method of any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one program, which, when loaded and executed by a processor, is used to implement the method according to any one of claims 1-7.
Citation Information
Patent Citations
Small file optimization storage method based on HDFS
CN103577123A
Method and device for storing data
CN106886375A
File storage method and device, electronic equipment and computer readable medium
CN114647379A
