A file writing method, device, equipment and medium
By determining the file type and using page copy technology to directly write data, it solves the problems of resource waste and low efficiency during small file writing, and improves writing efficiency and data reliability.
Patent Information
- Application Number
- CN202210331114.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-31
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-03-31
AI Technical Summary
In distributed storage systems, there are problems of resource waste and low efficiency in the file writing process. Especially after small files are processed through hierarchical aggregation, the client cannot directly perform operations such as reading, writing, deleting, and truncation, and the existing The technology is complex and resources are wasted.
By judging whether the target file is a large file formed through hierarchical aggregation processing, and creating temporary pages and target page caches according to the write type, using page copy technology to copy the data to the target page cache, and directly writing the data, reducing unnecessary Resource waste and number of interactions.
It improves the writing efficiency of small files when appending, reduces resource waste, and improves data reliability and storage product quality.
Smart Images

Figure CN114706823B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information technology, and in particular to a file writing method, device, equipment and medium. Background Art
[0002] In a distributed storage system, the data and metadata of files that users read and write through the kernel client are stored on the server side. Files with high user access frequency are usually placed in the source pool, and files with low user access frequency are placed in the migration pool. When a file is first created, its data is usually placed in the source pool, and after a period of time, it is migrated to the migration pool. The migration process is called data tiering. In some specific scenarios, a large number of small files will appear. In order to improve the efficiency of tiering of small files, the server side needs to aggregate small files into large files and then migrate the large files. Aggregation is accompanied by the tiering process. The tiered migration process improves the efficiency of the server side for batch processing of massive and small files, but the problem that comes with it is that the client cannot directly read, write, delete, truncate, and other operations on the small files after tiering and aggregation. In the prior art, the general technology adopted by the lib library is to locate the position of the small file in the large file according to the offset of the small file in the large file, and achieve the purpose of operating the small file by operating the large file. In particular, the process of the lib library writing hierarchical aggregate files is more complicated. According to whether the writing process makes the file larger, it can be divided into two writing methods: modification writing and appending writing: modification writing is to locate the position of the small file in the large file and perform a write operation on the large file; appending writing requires first reading the small file from the large file due to the difference in the underlying objects in the object storage device corresponding to the large and small files, and then merging the original data of the file and the data to be written through string operations, and then writing the merged result into the small file, and finally changing the metadata information of the large and small files.
[0003] However, the process of reading a small file from a large file requires first reading the data into the large file page cache, and then copying the data in the large file page cache to a user-state address. When writing, the data in the user-state address is copied to the page cache of the file, and then the flush thread is executed to write the data to the disk. But in fact, the read data has no direct use value to the user, and it is only for the integrity of the second write data, resulting in a waste of resources. In summary, how to reduce unnecessary resource waste and improve writing efficiency when writing files to optimize the file writing process needs to be further resolved. Summary of the invention
[0004] In view of this, an object of the present invention is to provide a file writing method, apparatus, device and medium, which can reduce unnecessary resource waste when writing a file to optimize the file writing process.
[0005] The specific plan is as follows:
[0006] In a first aspect, the present application discloses a file writing method, comprising:
[0007] Obtain a file write request for a target file carrying data to be written;
[0008] Determining whether the target file is a small file used to form a large file through hierarchical aggregation processing;
[0009] If the target file is the small file, determining whether the file write type corresponding to the file write request is a file append write type;
[0010] If the file writing type is a file append writing type, a corresponding temporary page and a target page cache are created for the target file, and the target file is read into the temporary page;
[0011] The target file in the temporary page is copied to the target page cache based on the page copy technology, and the data to be written is directly written into the target file.
[0012] Optionally, after obtaining the file write request carrying the data to be written for the target file, the method further includes:
[0013] Obtain the file number of the large file corresponding to the target file, the offset of the target file relative to the starting position of the large file, the hierarchical aggregation type corresponding to the target file, the sorting number of the object header of the object in the large file, the invalid space occupied by the target file and the size of the target file.
[0014] Optionally, the determining whether the target file is a small file used to form a large file through hierarchical aggregation processing includes:
[0015] Determining whether the target file is a small file used to form a large file through hierarchical aggregation processing according to the file number of the large file corresponding to the target file;
[0016] If the file number of the large file corresponding to the target file is 0, it is determined that the target file is not the small file, and the data to be written is directly written into the target file;
[0017] If the file number of the large file corresponding to the target file is not 0, the target file is determined to be the small file.
[0018] Optionally, the determining whether the file write type corresponding to the file write request is a file append write type includes:
[0019] Checking the writing position and writing content of the data to be written, and predicting and analyzing whether the size of the target file changes after writing based on the writing position and the writing content;
[0020] If the size of the target file after writing does not change, the file writing type is determined to be a file modification writing type, and the data to be written is directly written into the large file according to the offset of the target file relative to the starting position of the large file;
[0021] If the size of the target file changes after writing, it is determined that the file writing type is a file append writing type.
[0022] Optionally, the step of creating a corresponding temporary page and a target page cache for the target file and reading the target file into the temporary page includes:
[0023] A temporary page and a target page cache corresponding to the target file are created according to the offset of the target file relative to the starting position of the large file and the size of the target file, and the target file is read into the temporary page.
[0024] Optionally, copying the target file in the temporary page to the target page cache based on the page copy technology, and directly writing the data to be written into the target file, includes:
[0025] The temporary page is converted into an address and the data in the converted temporary page is copied to the target page cache, and the data to be written is directly written into the target file.
[0026] Optionally, after copying the target file in the temporary page to the target page cache based on the page copy technology and directly writing the to-be-written data into the target file, the method further includes:
[0027] The large file and metadata information of the written target file are updated according to the written target file.
[0028] In a second aspect, the present application discloses a file writing device, comprising:
[0029] A request acquisition module, used to acquire a file write request carrying data to be written for a target file;
[0030] A file determination module, used to determine whether the target file is a small file used to form a large file through hierarchical aggregation processing;
[0031] A file writing type judgment module, used for judging whether the file writing type corresponding to the file writing request is a file append writing type if the target file is the small file;
[0032] A temporary page reading module, used for creating a corresponding temporary page and a target page cache for the target file if the file writing type is a file append writing type, and reading the target file into the temporary page;
[0033] The page copy module is used to copy the target file in the temporary page to the target page cache based on the page copy technology, and directly write the data to be written into the target file.
[0034] In a third aspect, the present application discloses an electronic device, comprising:
[0035] Memory, used to store computer programs;
[0036] The processor is used to execute the computer program to implement the steps of the file writing method disclosed above.
[0037] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the file writing method disclosed above are implemented.
[0038] When writing a file, the present application first obtains a file write request for the target file carrying the data to be written, determines whether the target file is a small file used to form a large file through hierarchical aggregation processing, and if the target file is the small file, determines whether the file write type corresponding to the file write request is a file append write type. If the file write type is a file append write type, creates a corresponding temporary page and a target page cache for the target file, reads the target file into the temporary page, copies the target file in the temporary page to the target page cache based on the page copy technology, and writes the data to be written directly into the target file. It can be seen that when writing a file, the present application first determines whether the target file is a small file formed into a large file through hierarchical aggregation processing, and then determines the file write type corresponding to the write file request. When an append write request for a small file formed into a large file through hierarchical aggregation processing is obtained, the target file data in the temporary page is copied to the target page cache corresponding to the target file through the page copy technology, and the data to be written is directly written into the target file. Therefore, when an additional write request is made to a small file that is formed into a large file through hierarchical aggregation processing, the target file is read out and copied to the target page cache corresponding to the target file through the page copy technology, and then directly written, and the small file that is formed into a large file through hierarchical aggregation processing is read out and treated as a normal file for a simple additional write operation, so that the additional write process of the small file that is formed into a large file through hierarchical aggregation processing reduces the process of one copy and the process of character operation, and reduces the number of interactions between the kernel-mode client and the metadata server, thereby improving the writing efficiency of the small file that is formed into a large file through hierarchical aggregation processing during additional writing, while improving data reliability and improving the quality of storage products. In summary, the present application can reduce unnecessary resource waste and improve writing efficiency when writing files to optimize the writing process of files. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] 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 will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0040] Figure 1 A flow chart of a file writing method provided by this application;
[0041] Figure 2 Schematic diagram of the aggregation process and composition of large files provided for this application;
[0042] Figure 3 A specific file writing method flow chart provided for this application;
[0043] Figure 4 A schematic diagram of an additional writing process when the target file provided for this application is a small file formed into a large file through hierarchical aggregation processing;
[0044] Figure 5 A schematic diagram of the structure of a file writing device provided by this application;
[0045] Figure 6 A structural diagram of an electronic device provided for this application. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] In the prior art, the general technology used by the lib library is to locate the position of the small file in the large file according to the offset of the small file in the large file, and achieve the purpose of operating the small file by operating the large file. In particular, the process of writing the hierarchical aggregate file in the lib library is more complicated. According to whether the writing process makes the file larger, it can be divided into two writing methods: modification writing and appending writing: modification writing is to locate the position of the small file in the large file and perform a write operation on the large file; appending writing is different because of the difference in the underlying objects in the object storage device corresponding to the large and small files. First, the small file must be read out from the large file, and then the original file data and the data to be written are merged through string operations, and then the merged result is written to the small file, and finally the metadata information of the large and small files is changed. However, the process of reading a small file from a large file requires first reading the data into the large file page cache, and then copying the data in the large file page cache to a user-mode address. When writing, the data in the user state address is copied to the page cache of the file, and then the flush thread is executed to write the data to the disk. However, in fact, the read data has no direct use value for the user, and is only for the integrity of the second write data, resulting in a waste of resources. To this end, the present application provides a file writing method that can reduce unnecessary resource waste and improve writing efficiency when writing files to optimize the file writing process.
[0048] The embodiment of the present invention discloses a method for writing a file. Figure 1 Said method comprises:
[0049] Step S11: Obtain a file write request for a target file that carries data to be written.
[0050] In this embodiment, the file write request for data to be written refers to a request for modifying or appending to a target file, wherein the write request includes, but is not limited to, information about the size of the data to be written, information about the location of the data to be written, and information about the content of the data to be written. Further, a file write request carrying data to be written is obtained for the target file, so that the file write type can be judged through the file write request, and corresponding write operations can be performed on the file according to different file write types.
[0051] Step S12: Determine whether the target file is a small file that is used to form a large file through hierarchical aggregation processing.
[0052] In this embodiment, the large file is a file whose file size is greater than the first preset threshold; the small file is a file whose file size is less than the second preset threshold. It should be noted that the first preset threshold and the second preset threshold can be set according to actual conditions. When data is graded, a large number of small files will appear. In order to improve the efficiency of small file grading, the server will aggregate small files into large files for migration. The whole process is called the process of graded aggregation. Figure 2 As shown, in this process, the first preset threshold and the second preset threshold are set according to the actual situation. That is, the large file represents the entire file after the hierarchical aggregation operation, and the small file represents the aggregated file in the entire file after the hierarchical aggregation operation.
[0053] In this embodiment, the file write type of the target file is determined, and it is determined whether the target file is a small file used to form a large file through hierarchical aggregation processing. It can be understood that when the target file is not a small file that forms a large file through hierarchical aggregation processing, that is, when the target file is an ordinary file, the data to be written in the file write request is directly written into the target file. Through the above technical solution, the first step of judging the target file can be performed, that is, judging the file write type of the target file, and distinguishing the files based on the file write types corresponding to different target files, and then distinguishing their writing processes. When the target files are different files, direct writing operations can be performed; and when the target file is a small file that forms a large file through hierarchical aggregation processing, it is proved that the target file cannot be written in a direct writing manner. The first step of judging the target file facilitates the subsequent operation of the small file that forms a large file through hierarchical aggregation processing to write the file to be written into the target file.
[0054] Step S13: If the target file is the small file, determine whether the file write type corresponding to the file write request is a file append write type.
[0055] In this embodiment, when the target file is a small file that is formed into a large file through hierarchical aggregation processing, the file write type corresponding to it is judged through the obtained file write request, wherein the file write type includes modification write and append write. It can be understood that when the file write type is modification write, the file size of the target file will not increase after being written, and the file size of the target file will increase after the file append write. When the file write type corresponding to the file write request is judged to be modification write, the location of the small file is found in the large file and the file data to be written in the file write request is directly written into the target file; when the file write type corresponding to the file write request is judged to be append write, the subsequent steps are used to process the target file so as to write the file to be written of the append write type into the target file.
[0056] Step S14: If the file writing type is a file appending writing type, a corresponding temporary page and a target page cache are created for the target file, and the target file is read into the temporary page.
[0057] In this embodiment, when the file write type is an append write type, a corresponding temporary page and a target page cache are created for the target file, and the target file in the large file is directly read into the temporary page. Through the above scheme, the target file can be read from the corresponding large file, so that the read target file can be processed later to write the input data in the file write request into the target file.
[0058] Step S15: based on the page copy technology, copy the target file in the temporary page to the target page cache, and directly write the data to be written into the target file.
[0059] Specifically, the temporary page is converted into an address, and the data in the converted temporary page is copied to the target page cache, and the data to be written is directly written into the target file. That is, the target file is read into the temporary page, and copied to the target page cache corresponding to the target file through the page copy technology, and the dirty page of the target page cache is flushed to the disk, so that the small file originally in the large file is read out and written to the disk, and the target file is converted from a small file that forms a large file through hierarchical aggregation processing to an ordinary file, and then the data can be directly written to the target file, so as to achieve the purpose of writing the data to be written into the target file.
[0060] It can be seen that when writing a file, the present embodiment first determines whether the target file is a small file that forms a large file through hierarchical aggregation processing, and then determines the file writing type corresponding to the write file request. When an additional write request for a small file that forms a large file through hierarchical aggregation processing is obtained, the target file data in the temporary page is copied to the target page cache corresponding to the target file through the page copy technology, and the data to be written is directly written into the target file. Thus, when an additional write request is made to a small file that forms a large file through hierarchical aggregation processing, the target file is read out and copied to the target page cache corresponding to the target file through the page copy technology, and then directly written, and the small file that forms a large file through hierarchical aggregation processing is read out and treated as a normal file for a simple additional write operation, so that the additional write process of the small file that forms a large file through hierarchical aggregation processing reduces the process of one copy and the process of character operation, and reduces the number of interactions between the kernel state client and the metadata server, thereby improving the writing efficiency of the small file that forms a large file through hierarchical aggregation processing when appending, while improving data reliability and improving the quality of storage products. In summary, the present application can reduce unnecessary resource waste and improve writing efficiency when writing files to optimize the writing process of files.
[0061] See also Figure 3 As shown, the embodiment of the present invention discloses a specific file writing method. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution.
[0062] Step S21: Obtain a file write request for a target file that carries data to be written.
[0063] Step S22: Obtain the file number of the large file corresponding to the target file, the offset of the target file relative to the starting position of the large file, the hierarchical aggregation type corresponding to the target file, the sorting sequence number of the object header of the object in the large file, the invalid space occupied by the target file and the size of the target file.
[0064] In this embodiment, metadata information corresponding to the target file is obtained from a metadata server, including: the file number of the large file corresponding to the target file, the offset of the target file relative to the starting position of the large file, the hierarchical aggregation type corresponding to the target file, the sorting sequence number of the object header of the object in the large file, the invalid space occupied by the target file, and the size of the target file. Through the above technical solution, the metadata information corresponding to the target file is obtained from the metadata server, so as to facilitate the judgment of the target file and the creation of temporary pages in the subsequent file writing process through the metadata information.
[0065] Step S23: judging whether the target file is a small file used to form a large file through hierarchical aggregation processing according to the file number of the large file corresponding to the target file.
[0066] In this embodiment, judging whether the target file is a small file used to form a large file through hierarchical aggregation processing according to the file number of the large file corresponding to the target file includes: if the file number of the large file corresponding to the target file is 0, judging that the target file is not the small file, and directly writing the data to be written into the target file; if the file number of the large file corresponding to the target file is not 0, judging that the target file is the small file. Through the above technical solution, the large file number corresponding to the target file is checked to obtain the file type of the target file, so as to facilitate the subsequent writing operation on the target file through the file type.
[0067] Step S24: If the target file is the small file, determine whether the file write type corresponding to the file write request is a file append write type.
[0068] In this embodiment, if the target file is the small file, then judging whether the file write type corresponding to the file write request is a file append write type includes: checking the write position and the write content of the data to be written, and predicting and analyzing whether the size of the target file after writing changes based on the write position and the write content; if the size of the target file after writing does not change, then judging the file write type as a file modification write type, and directly writing the data to be written into the large file according to the offset of the target file relative to the starting position of the large file; if the size of the target file after writing changes, then judging the file write type as a file append write type. Through the above technical scheme, judging the file write type corresponding to the file write request, when the target file is a modification write, then directly writing to the target file; when the target file is an append write, then performing subsequent operations on the target file.
[0069] Step S25: If the file write type is a file append write type, create a temporary page and a target page cache corresponding to the target file according to the offset of the target file relative to the starting position of the large file and the size of the target file, and read the target file into the temporary page.
[0070] In this embodiment, the position corresponding to the target file is located according to the offset of the target file relative to the starting position of the large file, and a temporary page corresponding to the target file and a target page cache corresponding to the target file are created according to the size of the target file. Figure 4As shown, the target file data in the temporary page is subsequently copied to the target page cache through the page copy technology, and then flushed to the disk to the corresponding object storage device, so that the target file is saved in the form of a common file.
[0071] Step S26: based on the page copy technology, copy the target file in the temporary page to the target page cache, and directly write the data to be written into the target file.
[0072] In this embodiment, after the target file in the temporary page is copied to the target page cache based on the page copy technology and the data to be written is directly written into the target file, it also includes: updating the large file and the metadata information of the target file after writing according to the written target file.
[0073] It can be seen that in this embodiment, the kernel client obtains the metadata information of the corresponding target file from the metadata server, and judges the target file and creates a temporary page through the metadata information of the target file, so that the type of the target file can be accurately judged through the metadata information corresponding to the target file; on the other hand, a temporary page is created based on the size of the target file so that the created temporary page corresponds to the target file one by one, and it is guaranteed that there is sufficient space to accommodate the target file, so as to facilitate the subsequent smooth page copying and data writing.
[0074] See also Figure 5 The embodiment of the present application discloses a file writing device, comprising:
[0075] A request acquisition module 11, used to acquire a file write request carrying data to be written for a target file;
[0076] A file determination module 12, used to determine whether the target file is a small file used to form a large file through hierarchical aggregation processing;
[0077] A file writing type determination module 13 is used to determine whether the file writing type corresponding to the file writing request is a file appending writing type if the target file is the small file;
[0078] A temporary page reading module 14 is used to create a corresponding temporary page and a target page cache for the target file if the file writing type is a file appending writing type, and read the target file into the temporary page;
[0079] The page copy module 15 is used to copy the target file in the temporary page to the target page cache based on the page copy technology, and directly write the data to be written into the target file.
[0080] It can be seen that when writing a file, the present embodiment first determines whether the target file is a small file that forms a large file through hierarchical aggregation processing, and then determines the file writing type corresponding to the write file request. When an additional write request for a small file that forms a large file through hierarchical aggregation processing is obtained, the target file data in the temporary page is copied to the target page cache corresponding to the target file through the page copy technology, and the data to be written is directly written into the target file. Thus, when an additional write request is made to a small file that forms a large file through hierarchical aggregation processing, the target file is read out and copied to the target page cache corresponding to the target file through the page copy technology, and then directly written, and the small file that forms a large file through hierarchical aggregation processing is read out and treated as a normal file for a simple additional write operation, so that the additional write process of the small file that forms a large file through hierarchical aggregation processing reduces the process of one copy and the process of character operation, and reduces the number of interactions between the kernel state client and the metadata server, thereby improving the writing efficiency of the small file that forms a large file through hierarchical aggregation processing when appending, while improving data reliability and improving the quality of storage products. In summary, the present application can reduce unnecessary resource waste and improve writing efficiency when writing files to optimize the writing process of files.
[0081] In some specific embodiments, the file writing device further includes:
[0082] A metadata acquisition module is used to obtain the file number of the large file corresponding to the target file, the offset of the target file relative to the starting position of the large file, the hierarchical aggregation type corresponding to the target file, the sorting sequence number of the object header of the object in the large file, the invalid space occupied by the target file and the size of the target file.
[0083] In some specific embodiments, the file determination module 12 specifically includes:
[0084] A file number determination unit, configured to determine whether the target file is a small file used to form a large file through hierarchical aggregation processing according to the file number of the large file corresponding to the target file;
[0085] A first data writing unit, configured to determine that the target file is not the small file if the file number of the large file corresponding to the target file is 0, and directly write the data to be written into the target file;
[0086] The small file determination unit is used to determine that the target file is the small file if the file number of the large file corresponding to the target file is not 0.
[0087] In some specific embodiments, the file writing type determination module 13 specifically includes:
[0088] A written data checking unit, used to check the writing position and writing content of the data to be written, and to predict and analyze whether the size of the target file after writing changes based on the writing position and the writing content;
[0089] A second data writing unit is used to determine that the file writing type is a file modification writing type if the size of the target file after writing is not changed, and directly write the data to be written into the large file according to the offset of the target file relative to the starting position of the large file;
[0090] The append writing judgment unit is used to judge that the file writing type is a file append writing type if the size of the target file after writing changes.
[0091] In some specific embodiments, the temporary page reading module 14 is specifically used to: create a temporary page and a target page cache corresponding to the target file according to the offset of the target file relative to the starting position of the large file and the size of the target file, and read the target file into the temporary page.
[0092] In some specific embodiments, the page copy module 15 is specifically used to: convert the temporary page into an address and copy the converted data in the temporary page to the target page cache, and directly write the data to be written into the target file.
[0093] In some specific embodiments, the file writing device further includes:
[0094] The metadata information updating module is used to update the metadata information of the large file and the written target file according to the written target file.
[0095] Figure 6 An electronic device 20 provided in an embodiment of the present application is shown. The electronic device 20 may further include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the file writing method disclosed in any of the above embodiments. In addition, the electronic device 20 in this embodiment may be specifically an electronic computer.
[0096] In this embodiment, the power supply 23 is used to provide voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0097] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0098] The operating system 221 is used to manage and control the hardware devices on the electronic device 20, and the computer program 222 may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the file writing method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 may further include a computer program that can be used to complete other specific tasks.
[0099] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the aforementioned disclosed file writing method. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the aforementioned embodiments, and no further description will be given here.
[0100] Finally, 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 presence of other identical elements in the process, method, article or device including the elements.
[0101] The above is a detailed introduction to a file writing method, device, equipment and medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A file writing method, characterized in that: include: Obtain a file write request for a target file carrying data to be written; Determining whether the target file is a small file used to form a large file through hierarchical aggregation processing; If the target file is the small file, determining whether the file write type corresponding to the file write request is a file append write type; If the file writing type is a file append writing type, a corresponding temporary page and a target page cache are created for the target file, and the target file is read into the temporary page; Based on the page copy technology, the target file in the temporary page is copied to the target page cache, and the data to be written is directly written into the target file; After obtaining the file write request for the target file carrying the data to be written, the method further includes: Obtaining the file number of the large file corresponding to the target file, the offset of the target file relative to the starting position of the large file, the hierarchical aggregation type corresponding to the target file, the sorting sequence number of the object header of the object in the large file, the invalid space occupied by the target file and the size of the target file; The determining whether the file write type corresponding to the file write request is a file append write type includes: Checking the writing position and writing content of the data to be written, and predicting and analyzing whether the size of the target file changes after writing based on the writing position and the writing content; If the size of the target file after writing does not change, the file writing type is determined to be a file modification writing type, and the data to be written is directly written into the large file according to the offset of the target file relative to the starting position of the large file; If the size of the target file changes after writing, it is determined that the file writing type is a file append writing type.
2. The file writing method according to claim 1, characterized in that: The determining whether the target file is a small file used to form a large file through hierarchical aggregation processing includes: Determining whether the target file is a small file used to form a large file through hierarchical aggregation processing according to the file number of the large file corresponding to the target file; If the file number of the large file corresponding to the target file is 0, it is determined that the target file is not the small file, and the data to be written is directly written into the target file; If the file number of the large file corresponding to the target file is not 0, the target file is determined to be the small file.
3. The file writing method according to claim 1, characterized in that: The step of creating a corresponding temporary page and a target page cache for the target file and reading the target file into the temporary page includes: A temporary page and a target page cache corresponding to the target file are created according to the offset of the target file relative to the starting position of the large file and the size of the target file, and the target file is read into the temporary page.
4. The file writing method according to claim 1, characterized in that: The method of copying the target file in the temporary page to the target page cache based on the page copy technology, and directly writing the data to be written into the target file, includes: The temporary page is converted into an address and the data in the converted temporary page is copied to the target page cache, and the data to be written is directly written into the target file.
5. The file writing method according to any one of claims 1 to 4, characterized in that: After the target file in the temporary page is copied to the target page cache based on the page copy technology, and the data to be written is directly written into the target file, the method further includes: The large file and metadata information of the written target file are updated according to the written target file.
6. A file writing device, characterized in that: include: A request acquisition module, used to acquire a file write request carrying data to be written for a target file; A file determination module, used to determine whether the target file is a small file used to form a large file through hierarchical aggregation processing; A file writing type judgment module, used for judging whether the file writing type corresponding to the file writing request is a file append writing type if the target file is the small file; A temporary page reading module, used for creating a corresponding temporary page and a target page cache for the target file if the file writing type is a file append writing type, and reading the target file into the temporary page; A page copy module, used for copying the target file in the temporary page to the target page cache based on the page copy technology, and directly writing the data to be written into the target file; Wherein, the file writing device also includes: A metadata acquisition module, used to obtain the file number of the large file corresponding to the target file, the offset of the target file relative to the starting position of the large file, the hierarchical aggregation type corresponding to the target file, the sorting sequence number of the object header of the object in the large file, the invalid space occupied by the target file and the size of the target file; The file writing type judgment module includes: A written data checking unit, used to check the writing position and writing content of the data to be written, and to predict and analyze whether the size of the target file after writing changes based on the writing position and the writing content; A second data writing unit is used to determine that the file writing type is a file modification writing type if the size of the target file after writing is not changed, and directly write the data to be written into the large file according to the offset of the target file relative to the starting position of the large file; The append writing judgment unit is used to judge that the file writing type is a file append writing type if the size of the target file after writing changes.
7. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the file writing method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: Used to store computer programs; wherein, when the computer program is executed by a processor, the steps of the file writing method according to any one of claims 1 to 5 are implemented.
