A large file piecewise uploading method, device and medium thereof

By judging the size and metadata of fragmented files on the server side and determining the writing location, the access and adaptation problems of large file fragmented uploads in protocol interoperability scenarios are solved, and efficient file uploads and simplified processes are achieved.

CN115665168BActive Publication Date: 2024-10-11JINAN INSPUR DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211295556.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-21
Publication Date
2024-10-11
Estimated Expiration
2042-10-21

AI Technical Summary

Technical Problem

In the convergence scenario of protocol interoperability, the multi-part upload of large files has problems of inaccessibility and adaptation complexity. Existing solutions have low performance or require complex interface adaptation when combining multi-part files, and cannot meet the requirements for efficient upload.

Method used

By determining whether there is an uploaded fragmented file on the server, determine the fragmentation rules to accurately write data, use the size of the fragmented file to determine the writing location, and rewrite the tail fragment after completing the upload to avoid repeated reading and writing. Adapt to the interface.

Benefits of technology

It improves the efficiency of uploading large files, simplifies the process, reduces the workload, and directly obtains the complete file without creating an empty logical header file. The complexity of adapting to other protocols is also greatly reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115665168B_ABST
    Figure CN115665168B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device and medium for uploading large files in pieces, relates to the technical field of file uploading, and is used to realize the uploading of large files. In order to solve the problems existing in the currently used file piece uploading in the fusion scenario of protocol intercommunication, a method for uploading large files in pieces is provided. When uploading the first piece file, the file size of the current piece file is temporarily used as the piece rule for data writing; when uploading the piece file for the subsequent thread, it can be compared with the size of the previously uploaded piece file to determine the correct piece rule for writing data, and if it is determined that the first uploaded piece file is written incorrectly, it can be corrected. This method does not need to store the piece files separately and then combine them, which improves the upload efficiency, and does not need to create an empty logical header file, and further does not need to adapt the interface and characteristics for other protocols, reducing the complexity and workload of the process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of file uploading, and in particular to a method, device and medium for uploading large files in pieces. Background Art

[0002] At present, uploading large files is mainly achieved through uploading in pieces. In the fusion mode of protocol intercommunication, uploading large files based on the Amazon Simple Storage Service (S3) protocol is often achieved through sharding, but other protocols (NAS / CIFS / HDFS / FUSE / kernel client) need to identify and adapt when operating on the large file, otherwise the problem of inaccessibility will occur.

[0003] Since the server receiving the file cannot know the fragmentation rules of the client uploading the file, there are two commonly used solutions to solve the above adaptation problem: 1. Store each fragment file as a small file and reassemble it into a large file in the Complete stage (three stages of fragmented upload: Init stage, Put stage and Complete stage); 2. Do not reassemble it into a large file in the Complete stage, but create an empty logical header file for user access. Read, write, delete and other operations all use the logical header to find the corresponding fragment file for processing.

[0004] However, both of the above solutions have their own shortcomings. When combining shard files, Solution 1 needs to re-read and write, which greatly increases the latency and the performance cannot meet expectations. Solution 2 needs to adapt a large number of interfaces and features to meet the file access requirements of other protocols (especially NAS and kernel clients). The adaptation process is complicated and the workload is too large, which is not conducive to practical application.

[0005] Therefore, technicians in this field are in urgent need of a large file segment upload method to solve the problems existing in the currently used file segment upload in the fusion scenario of protocol intercommunication. Summary of the invention

[0006] The purpose of the present application is to provide a method, device and medium for uploading large files in pieces, so as to solve the problems existing in the currently used file piece upload in the fusion scenario of protocol intercommunication.

[0007] In order to solve the above technical problems, the present application provides a method for uploading large files in pieces, including:

[0008] Determine whether there are successfully uploaded segment files on the server;

[0009] If it does not exist, the file size of the corresponding shard file is used as the sharding rule, and the data is written to the corresponding position on the server;

[0010] If it exists, query the file size of the successfully uploaded segment file and determine whether it is smaller than the file size of the corresponding segment file;

[0011] If not, the file size of the queried shard file is used as the sharding rule to write data to the corresponding position on the server;

[0012] If so, the file size of the corresponding shard file is used as the sharding rule, and the data is written to the corresponding position of the server; after all subsequent threads complete uploading the shard files, the queried shard file is rewritten to the server as the tail shard.

[0013] Preferably, it also includes:

[0014] Query the server for metadata of each successfully uploaded segment file;

[0015] Determine whether the file size in the metadata is consistent with the file size of the corresponding segment file. If not, determine that the segment file is written abnormally.

[0016] Preferably, after querying the server for metadata of each successfully uploaded segment file, the method further includes:

[0017] The file sizes of all shard files are compared. If the file size of a shard file is inconsistent with the file sizes of multiple other shard files, it is determined that the shard file is written abnormally.

[0018] Preferably, after querying the server for metadata of each successfully uploaded segment file, the method further includes:

[0019] If there is a situation where the position of a fragment file with a smaller file size is before a fragment file with a larger file size, it is determined that the write of the fragment file with the smaller file size is abnormal.

[0020] Preferably, it also includes:

[0021] Clear the abnormal shard files and corresponding metadata written on the server.

[0022] Preferably, according to the sharding rule, writing data to the corresponding position of the server includes:

[0023] Determine the writing start position according to the product of the sharding rule and the shard number of the current shard file;

[0024] According to the write start position, write the data in the shard file to the corresponding position on the server.

[0025] Preferably, it also includes:

[0026] Generate an error report based on the abnormally written shard file and send it to the server;

[0027] The error report includes: the file size and fragment number of the abnormally written fragment file, the writing time, and the thread name of the thread executing the writing.

[0028] In order to solve the above technical problems, the present application also provides a large file segment uploading device, comprising:

[0029] The first judgment module is used to judge whether there is a successfully uploaded segment file in the server, if not, the first writing module is triggered, if yes, the second judgment module is triggered;

[0030] The first writing module is used to write data to the corresponding position of the server using the file size of the corresponding fragment file as a fragmentation rule;

[0031] The second judgment module is used to query the file size of the successfully uploaded segmented file and judge whether it is smaller than the file size of the corresponding segmented file. If not, the second writing module is triggered; if yes, the third writing module is triggered;

[0032] The second writing module is used to write data to the corresponding position of the server using the file size of the queried shard file as a sharding rule;

[0033] The third writing module is used to write data to the corresponding position of the server using the file size of the corresponding shard file as the sharding rule; after all subsequent threads complete uploading the shard files, the queried shard files are rewritten to the server as the tail shard.

[0034] Preferably, it also includes:

[0035] The traversal verification module is used to query the server for the metadata of each successfully uploaded segment file.

[0036] The first verification module is used to determine whether the file size in the metadata is consistent with the file size of the corresponding segment file. If not, it is determined that the segment file is written abnormally.

[0037] The second verification module is used to compare the file sizes of all the shard files. If the file size of a shard file is inconsistent with the file sizes of multiple other shard files, it is determined that the shard file is written abnormally.

[0038] The third verification module is used to determine that the writing of the fragment file with a smaller file size is abnormal if the position of the fragment file with a smaller file size exists before the fragment file with a larger file size.

[0039] The data clearing module is used to clear abnormally written shard files and corresponding metadata on the server.

[0040] The report generation module is used to generate an error report based on the shard file with abnormal writing and send it to the server.

[0041] In order to solve the above technical problems, the present application also provides a large file segment uploading device, comprising:

[0042] Memory for storing computer programs;

[0043] The processor is used to implement the steps of the above-mentioned large file segment uploading method when executing the computer program.

[0044] In order to solve the above technical problems, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned large file segment uploading method are implemented.

[0045] The present application provides a method for uploading large files in pieces. When uploading a piece file for the first time, the file size of the current piece file is temporarily used as the piece rule for writing data; when the subsequent threads upload piece files, it is determined whether the file size of the piece file uploaded for the first time is smaller than the file size of the current piece file; if it is smaller, according to the characteristics of the piece files, only the size of the tail piece may be smaller than the remaining pieces. Therefore, at this time, the piece file uploaded for the first time is the tail piece. Correspondingly, the piece files uploaded subsequently are definitely not the tail piece, and their file sizes can be used as the piece rule to determine the writing position. In addition, since the file size is used as the piece rule for writing data when the piece file is uploaded for the first time, because the piece file written for the first time is the tail piece, the data writing may not be correct. Therefore, after all subsequent threads complete the upload task, the method re-writes the piece file written for the first time at the tail end of the remaining uploaded data to complete the piece upload of the large file. Since this method completes the upload of large files by calculating the data writing position, there is no need to store each fragment file in the form of small files and then re-read and write them into large files, which greatly increases the upload efficiency and improves the server performance. In addition, the large files uploaded by this method can exist directly in the form of files, without creating empty logical header files, and there is no need to adapt interfaces and features to adapt to other protocols, which reduces the complexity and workload of the process.

[0046] The large file segment uploading device and computer-readable storage medium provided in this application correspond to the above method and have the same effect as above. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0048] Figure 1 A flowchart of a method for uploading large files in pieces provided by the present invention;

[0049] Figure 2 A flow chart of a method for determining a write start position provided by the present invention;

[0050] Figure 3 A flowchart of a method for verifying the legitimacy of a slice file provided by the present invention;

[0051] Figure 4 A flowchart of another large file segment uploading method provided by the present invention;

[0052] Figure 5 A structural diagram of a large file segment uploading device provided by the present invention;

[0053] Figure 6 A structural diagram of another large file segment uploading device provided by the present invention. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0055] The core of this application is to provide a method, device and medium for uploading large files in pieces.

[0056] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0057] With the continuous development of network technology, users' demand for uploading large files is also increasing. However, due to its high time consumption and instability, it is relatively difficult to upload the entire file at one time. Currently, large files are mainly uploaded through multi-part uploading.

[0058] It is easy to understand that the large files mentioned in this application do not have a specific size range or standard, but refer to files that, in actual applications, technicians consider it inappropriate to upload the entire file at one time based on actual needs.

[0059] The so-called multi-part upload is to divide the file to be uploaded into multiple data blocks (called Parts) according to a certain size (i.e. the fragmentation rule) and upload them separately. After uploading, the server will aggregate and integrate all the uploaded files into the original file. Multi-part upload can not only avoid the problem of having to upload from the beginning of the file due to poor network environment, but also use multi-threading to send different block data concurrently, improve sending efficiency and reduce sending time.

[0060] However, in the current fusion mode of protocol intercommunication, since the server cannot directly obtain the client's fragmentation rules for splitting large files from the client during the process of uploading large files from the client to the server, the server cannot directly write the received fragmented files to the specified location, that is, it is impossible to directly receive large files through multi-threaded parallel uploading.

[0061] Currently, the following two methods are used:

[0062] First, each fragment file is uploaded as a separate file and stored in the server. After receiving all the fragment files, the server re-reads each file and combines them to obtain the final uploaded file. However, the disadvantage of this method is that the uploaded file needs to be read repeatedly, which greatly affects the efficiency of file uploading, and a large number of intermediate files (related to the number of fragment files) are generated during the upload process, wasting a lot of resources.

[0063] Second, after each shard file is successfully uploaded, it is not combined, but an empty logical header file is created to provide access to the user. Since the shard files are uploaded based on the S3 protocol and there is no complete large file, the interface and feature adaptation are required to adapt to other protocols to access the shard files. It is easy to understand that in the scenario of multi-protocol intercommunication, the adaptation process is very tedious and complicated.

[0064] Therefore, in order to solve the above problems, this application provides a method for uploading large files in pieces, such as Figure 1 As shown, including:

[0065] S11: Determine whether there is a successfully uploaded segment file in the server, if not, go to step S12, if yes, go to step S13.

[0066] To ensure maximum upload efficiency, each thread is preferably configured to upload the corresponding segmented files to the server in parallel, that is, each thread needs to execute this method when uploading segmented files.

[0067] S12: Using the file size of the corresponding fragment file as a fragmentation rule, write data to the corresponding position of the server.

[0068] It is easy to know that in the process of splitting a large file into several fragment files according to the fragmentation rules, there are two situations: first, the file size of the large file can be divided by the fragmentation rules, that is, the file sizes of all fragment files are the same, and are equal to the file size specified by the fragmentation rules; second, the file size of the large file cannot be divided by the fragmentation rules, then the file size of the tail fragment is smaller than the file size specified by the fragmentation rules, and the remaining fragment files are the same size as the fragmentation rules.

[0069] Therefore, in step S12, since the current thread is the first thread to upload the segmented file (for the convenience of explanation, it will be referred to as thread A below), and there is no segmented file uploaded before this to provide a reference for the segmentation rules, it is temporarily considered that the segmented file uploaded by the current thread is not the last segment. The starting position of the data to be written is determined based on its file size as the segmentation rule, and the data is written to the server.

[0070] S13: Query the file size of the successfully uploaded segmented file and determine whether it is smaller than the file size of the corresponding segmented file. If not, go to step S14; if so, go to step S15.

[0071] From the above, it can be seen that the purpose of step S11 is to distinguish whether the current thread is the thread that completes the uploading of the segmented file first (that is, to distinguish thread A from other threads), so step S13 corresponds to other threads, and the segmented files that have been successfully uploaded and can be queried by other threads are the segmented files uploaded by thread A.

[0072] It can be seen from the file size characteristics of each shard file divided according to the sharding rules mentioned above that by comparing the file size with the shard file uploaded by thread A, it can be determined whether there is a tail shard in the shard files uploaded by the current thread and thread A (because only the tail shard may have a file size smaller than the remaining shards).

[0073] That is, the purpose of step S13 is to find the tail fragment. Specifically:

[0074] When entering the No branch, the size of the shard file uploaded by thread A is greater than or equal to the size of the shard file corresponding to the current thread, indicating that the shard file corresponding to thread A must not be the tail shard (it is impossible to determine whether the current thread corresponds to the tail shard). The size of the shard file corresponding to thread A can be used as the sharding rule.

[0075] When entering the yes branch, the size of the shard file uploaded by thread A is smaller than the size of the shard file corresponding to the current thread, indicating that the shard file corresponding to the current thread must not be the tail shard (it is impossible to determine whether thread A corresponds to the tail shard). The size of the shard file corresponding to the current thread can be used as the sharding rule.

[0076] It should also be noted that, in fact, if the judgment condition of step S13 is further subdivided, it is possible to determine whether the current thread and thread A are tail fragments. For example, the comparison of the fragment file sizes of the current thread and thread A is divided into three branches: less than, equal to, and greater than. The less than branch corresponds to the current thread being the tail fragment, the equal to branch corresponds to neither being the tail fragment, and the greater than branch corresponds to thread A being the tail fragment. However, in actual applications, the judgment standard of the above step S13 is sufficient to determine the correct fragmentation rule without increasing the difficulty of judgment, so this application preferably uses the judgment method of step S13.

[0077] S14: Using the file size of the queried shard file as a sharding rule, write data to the corresponding position of the server.

[0078] As described above, the judgment branch corresponding to step S14 can determine that the shard file corresponding to thread A is definitely not the tail shard, so it is accurate to use the shard file size uploaded by thread A as the shard rule, and the correct write start address can be obtained to write data to the server.

[0079] S15: Using the file size of the corresponding shard file as a sharding rule, write data to the corresponding position of the server; after all subsequent threads complete uploading the shard files, rewrite the queried shard file as the tail shard to the server.

[0080] As described above, the judgment branch corresponding to step S15 can determine that the slice file corresponding to thread A is the tail slice. Since there is only one tail slice, the slice file size corresponding to the current thread is accurate as the slice rule, and the correct write start address can be obtained to write data to the server. In addition, since thread A previously used its slice file size as the slice rule to determine the write start address when writing the slice file, it is judged that thread A corresponds to the tail slice, and the file size of the tail slice cannot be used as the slice rule, and the write error of thread A needs to be corrected. Knowing that thread A is the tail slice, after all subsequent threads have finished writing the slice files, the tail slice of thread A can be rewritten to the very end.

[0081] It should also be noted that, for determining the write start address of the current shard file according to the sharding rule, this embodiment provides a better implementation scheme, based on the characteristics of splitting a large file according to the sharding rule, such as Figure 2 As shown, specifically:

[0082] S21: Determine the writing start position according to the product of the sharding rule and the shard number of the current shard file.

[0083] S22: According to the write start position, write the data in the shard file to the corresponding position of the server.

[0084] It is easy to understand that a shard file is essentially a data block of a divided large file. Therefore, the shard number is used to indicate which data block of the large file the shard file is. Under the premise of determining the shard rule, the size of other data blocks excluding the tail data block can be known. Therefore, the data write start address of the current shard file can be quickly and easily determined by multiplying the shard rule and the shard number.

[0085] The present application provides a method for uploading large files in pieces, which utilizes the characteristics of dividing a large file into several pieces. By first temporarily determining that the thread that uploads the piece file for the first time is not uploading the tail piece, the file size is used as the piece rule to determine the data writing starting position to complete the first upload, so that when other threads upload the piece file later, the metadata of the previously uploaded piece file can be obtained from the server, and then the file size is compared with the own piece file, so that it can be determined whether the first uploaded piece file is the tail piece, and then the file size of the party that is not the tail piece is used as the piece rule to determine the writing starting address, so that the piece data can be accurately written. Therefore, all threads except the thread that completes the upload for the first time can obtain accurate piece rules by comparing the file size with the piece file uploaded for the first time, so as to ensure that the data is written correctly. When the first piece file is written incorrectly, it means that the first upload is the tail piece. According to the characteristics of the tail piece, after the remaining threads complete the data upload, it can be rewritten to the tail end to complete the correction, and finally obtain the correct large file. The above method directly writes data by determining the starting position of data writing, without dividing it into a large number of sub-files for storage and then reorganizing it. At most, only the tail fragment needs to be rewritten, which greatly improves the efficiency of uploading large files and improves the performance of the server. At the same time, the above method can directly obtain the uploaded large file without setting an empty logical header file, and there is no need to adapt the characteristics and interfaces of other protocols to support access, which simplifies the upload process and also improves the upload efficiency of large files.

[0086] It can be seen from the above embodiments that in the entire large file upload process, under ideal conditions, only the first uploaded segmented file may have a write error problem during the upload process, and it can be corrected before the upload is completed according to the above method to obtain an accurate large file. However, the actual working conditions are more complicated and full of uncertainty, and it cannot be guaranteed to be under ideal conditions all the time. Some segmented files may be uploaded incorrectly due to problems with the thread itself or problems in the data transmission process. At this time, in order to ensure the accuracy of the large file upload, it is necessary to check the subsequent uploaded segmented files.

[0087] This embodiment provides a preferred solution for checking the accuracy of file upload, such as Figure 3 As shown, the above method also includes:

[0088] S31: Query the server for metadata of each successfully uploaded segment file.

[0089] S32: Determine whether the file size in the metadata is consistent with the file size of the corresponding segment file. If not, determine that the segment file is written abnormally.

[0090] It is easy to know that in actual applications, after each thread successfully uploads a segmented file, it will also write the metadata of the segmented file to the server, which is convenient for subsequent inquiries to grasp the status of the segmented file. In this embodiment, the metadata of the segmented file successfully uploaded by the server is compared with the size of the segmented file uploaded by the client upload thread to check whether the content of the segmented file on both sides of the server and the client is consistent. If the size is different, it means that an abnormality occurs during the segmented file upload process, and the file writing also occurs abnormally, and the uploaded data is incorrect.

[0091] Furthermore, this embodiment also provides a preferred implementation scheme for checking whether the uploaded fragmented files are correct. Figure 3 As shown, the above method also includes:

[0092] S33: Compare the file sizes of all the segment files. If the file size of a segment file is inconsistent with the file sizes of multiple other segment files, it is determined that the segment file is written abnormally.

[0093] As can be seen from the above embodiment, step S31 is actually equivalent to traversing the file sizes of each shard file uploaded to the server. Accordingly, when traversing, the file sizes of all shard files can also be compared with each other. Due to the characteristics of shard files, only the tail shard may have a file size smaller than other shard files, and the file sizes of the remaining shard files should be the same. Therefore, when there is a shard file that is inconsistent with the size of two or more other shard files at the same time, the shard file can be determined to be abnormal.

[0094] Similarly, in addition to the preferred solutions provided by the above two embodiments, this embodiment also provides a solution for checking whether the uploaded fragmented files are correct, such as Figure 3 As shown, the above method also includes:

[0095] S34: If there is a situation where the position of the fragment file with a smaller file size is before the fragment file with a larger file size, it is determined that the writing of the fragment file with a smaller file size is abnormal.

[0096] Similarly to the above, only the tail fragment may have a file size smaller than other fragment files, and the tail fragment is located at the end of the file. Therefore, when traversing the metadata of all uploaded fragment files in step S31, it is determined whether there is a fragment file with a smaller file size that is located before the fragment file with a larger file size. If so, it can be considered that the fragment file with a smaller file size is written abnormally.

[0097] It can be seen from the preferred solution provided by the above embodiment that after each thread uploads its own segment file, the segment file can be verified by traversing the metadata of each segment file on the server and comparing the file size, that is, steps S32, S33 and S34 are all after step S31, but there is no order relationship between them. Figure 3 The above is only one possible implementation method. The three verification methods can be used alone or in combination. The ultimate goal is to determine the legitimacy of each shard file. To ensure the accuracy of the verification, the above three verification methods are usually used simultaneously.

[0098] Further, after determining the abnormally written shard file through the inspection method provided in the above embodiment, the erroneous data needs to be cleared. A possible implementation scheme is as follows: Figure 3 As shown, the above method also includes:

[0099] S35: Clear the abnormally written shard files and corresponding metadata in the server.

[0100] It is easy to understand that when each thread writes a shard file, the writing starting position is determined by the shard number and shard rule. Therefore, the shard number can also be included in the metadata of the shard file. The server can use this to determine the thread and shard file with upload abnormalities and require the client to re-upload it without re-uploading the entire large file, thereby realizing the verification of large files and correction of abnormal data.

[0101] It can be seen from the above embodiment that the segmented upload of files is divided into the Init stage, the Put stage and the Complete stage. The process of uploading segmented files to the server by the above threads occurs in the Put stage, and the process of verifying the legitimacy of the segmented files provided in this embodiment occurs in the Complete stage.

[0102] Similarly, during the application process of the server, the operation and maintenance personnel are concerned about the abnormalities that occur in the server. Therefore, this embodiment further provides a preferred implementation scheme based on the above embodiment, such as Figure 3 As shown, the above method also includes:

[0103] S36: Generate an error report based on the abnormally written shard file and send it to the server.

[0104] The error report includes, but is not limited to: the file size and shard number of the abnormally written shard file, the writing time, and the thread name of the thread executing the writing.

[0105] It should be noted that if other devices or personnel have a need to be informed of write anomalies, the error report can also be returned to the corresponding device, such as a mobile terminal or portable device carried by the operation and maintenance personnel.

[0106] The preferred solution provided in this embodiment implements the verification of the legality of the uploaded shard files in three different ways, which guarantees the accuracy of the legality verification to the greatest extent and the legality of the large file upload. In addition, after determining the abnormally written shard file, the corresponding data is cleared to facilitate the subsequent data rewriting by the shard number, realize the correction of the abnormal data, and further improve the accuracy of the file upload. Finally, the corresponding error report is generated based on the abnormally written shard file and returned to the server to inform the relevant personnel of the abnormal writing and the abnormal thread and time during the large file upload process, so as to better help the operation and maintenance personnel to timely investigate and solve the problem, which is conducive to maintaining the normal and stable operation of the server.

[0107] In order to more clearly illustrate the method for uploading a large file in pieces provided by the present application, the method provided by the present application is further explained from the perspective of practical application with reference to an example. Figure 4 As shown, the method includes:

[0108] S41: Determine whether the first data block file exists in the server, if not, go to step S42, if yes, go to step S44.

[0109] Among them, the first data block file is an intermediate file used to temporarily store the fragment file data. In the embodiment, it is specifically used to store the data uploaded by thread A.

[0110] S42: Create a first data block file and determine whether the creation is successful. If so, go to step S43; if not, go to step S41.

[0111] S43: Using the file size of the corresponding shard file as a sharding rule, write the shard file data to the corresponding position of the first data block file, and write the corresponding metadata to the server-side Extra_pool additional pool.

[0112] Extra_pool: A storage pool used to store metadata information for segment uploads, to facilitate breakpoint resuming.

[0113] The data writing of the slice file is to open the corresponding slice file through the file descriptor of the slice file, read the data and write it to the corresponding position of the first data block file.

[0114] S44: Determine whether the file size in the queried metadata is smaller than the file size of the corresponding segment file. If not, go to step S45; if so, go to step S46.

[0115] S45: Determine whether there is a second data block file. If not, rename the first data block file to the second data block file, determine the starting position according to the file size in the queried metadata and the fragment number of the corresponding fragment file, and write the fragment file data to the second data block file.

[0116] From the above, it can be seen that under the No branch of step S44, it means that what thread A uploaded must not be the tail fragment, that is, the data in the first data block file is not the tail fragment data, and the fragmentation rule adopted by thread A is correct. Therefore, thread A writes correctly, and the data in the first data block file is also determined to be written correctly.

[0117] Furthermore, when it is determined that thread A is not the tail fragment, the fragment file size of thread A can be used as a fragmentation rule to correctly write all subsequent thread fragment files and put them into the second data block file.

[0118] S46: Determine whether the second data block file exists, and create it if not, and determine the starting position according to the file size of the corresponding fragment file and the fragment number of the corresponding fragment file, and write the fragment file data into the second data block file.

[0119] From the above, it can be seen that in the yes branch of step S44, it means that the fragment file uploaded by thread A is the tail fragment, then other threads must not be the tail fragments, so other threads can determine the correct fragmentation rules based on their corresponding fragment file sizes and write the data into the second data block file.

[0120] In addition, in this branch, the fragmentation rule adopted by thread A is wrong (when writing, thread A assumes that it is not the tail fragment and writes data with its own file size), that is, the data writing error in the first data block file needs to be corrected, which is the subsequent step S47.

[0121] S47: After all threads have finished uploading, the data in the first data block file is written into the second data block file with the file size of the second data block file as the starting position, and the first data block file is deleted.

[0122] It should be noted that, although step S45 and step S46 are not written out, it is actually necessary to write the corresponding metadata to the server-side Extra_pool additional pool after the shard file is uploaded, so as to meet the requirements of the shard file legitimacy verification method in the above embodiment. The above steps S45 and step S46 are not written out because only in the process of uploading the shard file, the metadata of the shard file uploaded by non-thread A is not concerned.

[0123] In addition, it can be seen from the above step S46 that at this time, it is determined that thread A corresponds to the tail fragment, and the data of the first data block file is the tail fragment data, so after other threads have completed uploading, it is only necessary to write the data of the first data block file to the tail of the second data block file to achieve correction.

[0124] It is easy to understand that the first data block file is used to store uncertain shard file data, which in this embodiment is to temporarily store the uploaded data of thread A, and the second data block file is used to store the uploaded data that has been confirmed to be correct. During the entire large file upload process, at most two intermediate files, the first data block file and the second data block file, appear, and after the upload process is completed, only the second data block file remains, which is the uploaded large file.

[0125] It should also be noted that since the first data block file and the second data block file are intermediate files, it is preferred to set their attributes to invisible. When the entire large file upload process is completed, that is, when a second data block file is processed, the second data block file is renamed to the file name of the uploaded large file, and its attributes are set to visible, thus completing the entire large file upload process. As for the legitimacy check of the fragmented files in the subsequent Complete stage, it has been clearly explained in the above embodiment, so this embodiment will not be repeated here.

[0126] In addition, the setting of the intermediate state file also helps to determine the only thread A. In practical applications, multiple threads are usually preferred to upload shard files concurrently, so it is easy for multiple threads to meet the situation that no uploaded shard files are found in the server at the same time, and it is not easy to get the only thread A at this time.

[0127] During the creation process of the first data block file, even if multiple threads execute the operation of creating the first data block file, due to factors such as the order of execution, only one thread can create it successfully, and the other threads will fail to create after the first data block file has been created, thereby determining the first thread that successfully uploads the shard file, that is, thread A.

[0128] The present embodiment provides a method for uploading large files in pieces, the purpose of which is to determine the slicing rules of large files to accurately write data. Specifically, when thread A uploads data, it is temporarily determined that it is not the tail slicing to upload data. When subsequent threads upload, the correct slicing rules can be determined by comparing the slicing file size with thread A to complete data uploading. Similarly, when it is determined that thread A writes an error, it is only possible that it is because thread A corresponds to the tail slicing. Then, only the original written data needs to be cleared and rewritten at the tail end to complete the data correction and ensure the accuracy of large file upload. The above-mentioned large file upload method does not need to be divided into small files for storage and rewriting, which improves the upload efficiency and performance, and does not need to create an empty logical header file for access, so there is no need to adapt the interfaces and characteristics between different protocols, reducing the complexity and workload of the operation. In addition, through the above method, there are at most two intermediate state files in the entire upload process, namely the first data block file and the second data block file, and under normal working conditions, only the second data block file is left, that is, the uploaded large file, which can also effectively solve the problem of resource waste and better meet the needs of the actual application of the server.

[0129] In the above embodiment, a method for uploading a large file in pieces is described in detail, and the present application also provides an embodiment corresponding to a device for uploading a large file in pieces. It should be noted that the present application describes the embodiments of the device part from two perspectives, one is based on the perspective of functional modules, and the other is based on the perspective of hardware.

[0130] From the perspective of functional modules, this embodiment provides a large file segment uploading device, including:

[0131] The first judgment module 51 is used to judge whether there is a segment file that has been successfully uploaded in the server, and if not, the first writing module is triggered; if so, the second judgment module is triggered;

[0132] A first writing module 52 is used to write data to a corresponding position of the server using the file size of the corresponding fragment file as a fragmentation rule;

[0133] The second judgment module 53 is used to query the file size of the successfully uploaded segmented file and judge whether it is smaller than the file size of the corresponding segmented file. If not, the second writing module is triggered; if yes, the third writing module is triggered;

[0134] The second writing module 54 is used to write data to the corresponding position of the server using the file size of the queried shard file as a sharding rule;

[0135] The third writing module 55 is used to write data to the corresponding position of the server using the file size of the corresponding segment file as the segment rule; after all subsequent threads complete uploading the segment files, the queried segment file is rewritten to the server as the last segment.

[0136] Preferably, it also includes:

[0137] The traversal verification module is used to query the server for the metadata of each successfully uploaded segment file.

[0138] The first verification module is used to determine whether the file size in the metadata is consistent with the file size of the corresponding segment file. If not, it is determined that the segment file is written abnormally.

[0139] The second verification module is used to compare the file sizes of all the shard files. If the file size of a shard file is inconsistent with the file sizes of multiple other shard files, it is determined that the shard file is written abnormally.

[0140] The third verification module is used to determine that the writing of the fragment file with a smaller file size is abnormal if the position of the fragment file with a smaller file size exists before the fragment file with a larger file size.

[0141] The data clearing module is used to clear abnormally written shard files and corresponding metadata on the server.

[0142] The report generation module is used to generate an error report based on the shard file with abnormal writing and send it to the server.

[0143] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.

[0144] The present embodiment provides a device for uploading large files in pieces. The first judgment module is used to query whether there is a successfully uploaded piece file in the server side, so as to determine whether the current thread is the first thread to upload the piece file, that is, whether it is thread A; if so, the first writing module is used to temporarily determine that it is not the tail piece and write the data to the corresponding position in the server side; if not, the second judgment module is used to further determine whether the queried file size is smaller than the file size of its own piece file; if not, it means that thread A must not be the tail piece, and the second writing module is used to write data according to the file size corresponding to thread A as the piece rule; if less than, it means that thread A is the tail piece, then other threads must not be the tail piece, and the third writing module is used to write data according to the file size corresponding to the thread itself as the piece rule; further, when thread A writes incorrectly, the third writing module is used to correct the data uploaded by thread A, and the tail piece data is rewritten to the tail end of the data uploaded by other threads, so as to obtain the final correct large file. This device directly writes data by determining the starting position of data writing, without dividing it into a large number of sub-files for storage and then reorganizing it. At most, only the tail fragment needs to be rewritten, which greatly improves the efficiency of uploading large files and improves the performance of the server. At the same time, the above device can directly obtain the uploaded large files without setting an empty logical header file, and there is no need to adapt the characteristics and interfaces of other protocols to support access, which simplifies the upload process and also improves the upload efficiency of large files.

[0145] Figure 6 A structural diagram of a large file segment uploading device provided in another embodiment of the present application is shown as follows: Figure 6 As shown, a large file segment uploading device includes: a memory 60, for storing a computer program;

[0146] The processor 61 is used to implement the steps of a method for uploading a large file in pieces as described in the above embodiment when executing a computer program.

[0147] The large file segment uploading device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.

[0148] Among them, the processor 61 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 61 can be implemented in at least one hardware form of a digital signal processor (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 61 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 61 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 61 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0149] The memory 60 may include one or more computer-readable storage media, which may be non-transitory. The memory 60 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 60 is at least used to store the following computer program 601, wherein, after the computer program is loaded and executed by the processor 61, it can implement the relevant steps of a large file segment upload method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 60 may also include an operating system 602 and data 603, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 602 may include Windows, Unix, Linux, etc. Data 603 may include but is not limited to a large file segment upload method, etc.

[0150] In some embodiments, a large file segment uploading device may further include a display screen 62 , an input / output interface 63 , a communication interface 64 , a power supply 65 , and a communication bus 66 .

[0151] Those skilled in the art will understand that Figure 6 The structure shown in the figure does not constitute a limitation on a device for uploading a large file in segments, and may include more or fewer components than those shown in the figure.

[0152] An embodiment of the present application provides a large file segment uploading device, including a memory and a processor. When the processor executes a program stored in the memory, it can implement the following method: a large file segment uploading method.

[0153] The present embodiment provides a large file segment upload device, which executes a computer program stored in a memory through a processor to query whether there is a successfully uploaded segment file in the server to determine whether the current thread is the first thread to upload the segment file, that is, whether it is thread A; if so, it is temporarily determined that it is not the tail segment and writes the data to the corresponding position in the server; if not, it is further determined whether the queried file size is smaller than the file size of its own segment file; if not, it means that thread A must not be the tail segment, and data is written according to the file size corresponding to thread A as the segment rule; if less than, it means that thread A is the tail segment, then other threads must not be the tail segment, and data is written according to the file size corresponding to the thread itself as the segment rule; further, when thread A writes an error, the tail segment data is rewritten to the tail end of the data uploaded by other threads to obtain the final correct large file. The present device directly writes data by determining the starting position of data writing, without the need to divide it into a large number of sub-files for storage and then reorganize it. At most, only the tail segment needs to be rewritten, which greatly improves the efficiency of large file upload and improves the performance of the server. At the same time, large files can be uploaded directly through the above device without setting an empty logical header file, and there is no need to adapt the characteristics and interfaces of other protocols to support access, which simplifies the upload process and also improves the upload efficiency of large files.

[0154] Finally, the present application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.

[0155] It is understandable that if the method in the above embodiment is implemented in the form of 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 application is essentially 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, and the computer software product is stored in a storage medium to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0156] A computer-readable storage medium provided by the present embodiment can, when the computer program stored therein is executed, query whether there is a successfully uploaded segment file in the server to determine whether the current thread is the first thread to upload the segment file, that is, whether it is thread A; if so, it is temporarily determined that it is not the tail segment and the data is written to the corresponding position in the server; if not, it is further determined whether the queried file size is smaller than the file size of its own segment file; if not, it means that thread A must not be the tail segment, and data is written according to the file size corresponding to thread A as the segmentation rule; if less than, it means that thread A is the tail segment, then other threads must not be the tail segment, and data is written according to the file size corresponding to the thread itself as the segmentation rule; further, when thread A writes incorrectly, the tail segment data is rewritten to the tail end of the data uploaded by other threads to obtain the final correct large file, without the need to be divided into a large number of sub-files for storage and then reorganized, and at most only the tail segment needs to be rewritten, which reduces the number of file rereading times, greatly improves the efficiency of large file upload, and improves the performance of the server. At the same time, there is no need to set an empty logical header file, so there is no need to adapt the characteristics and interfaces of other protocols to support access, which simplifies the large file upload process and also improves the upload efficiency.

[0157] The above is a detailed introduction to a large file segment uploading method, device and medium provided by the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

[0158] It should also be noted that, in this specification, 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 "comprise", "include" 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, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

Claims

1. A method for uploading a large file in pieces, characterized in that: include: Determine whether there is a successfully uploaded segment file in the server; wherein the segment file is obtained by segmenting a large file into fixed-size segments; If it does not exist, the file size of the segmented file to be uploaded is used as the segmentation rule to write data to the corresponding position of the server; If it exists, query the file size of the segment file successfully uploaded for the first time, and determine whether it is smaller than the file size of the segment file to be uploaded; If not, the file size of the queried shard file is used as the sharding rule to write data to the corresponding position of the server; If yes, the file size of the segmented file to be uploaded is used as the segmentation rule, and data is written to the corresponding position of the server; after all subsequent threads complete uploading the segmented file, the queried segmented file is rewritten to the server as the tail segment; Wherein, according to the sharding rule, writing data to a corresponding position of the server includes: Determine the writing start position according to the product of the sharding rule and the shard number of the current shard file; According to the write start position, the data in the segment file is written to the corresponding position of the server.

2. The method for uploading large files in pieces according to claim 1, characterized in that: Also includes: Query the server for metadata of each of the successfully uploaded segment files; It is determined whether the file size in the metadata is consistent with the file size corresponding to the segment file. If not, it is determined that the segment file is written abnormally.

3. The method for uploading large files in pieces according to claim 2, characterized in that: After querying the server for metadata of each of the successfully uploaded segment files, the method further includes: The file sizes of all the segment files are compared. If the file size of the segment file is inconsistent with the file sizes of multiple other segment files, it is determined that the segment file is written abnormally.

4. The method for uploading large files in pieces according to claim 2, characterized in that: After querying the server for metadata of each of the successfully uploaded segment files, the method further includes: If there is a situation where the position of the segment file with a smaller file size is before the segment file with a larger file size, it is determined that the write of the segment file with a smaller file size is abnormal.

5. The method for uploading a large file in pieces according to any one of claims 2 to 4, characterized in that: Also includes: Clear the abnormally written segment files and corresponding metadata in the server.

6. The method for uploading a large file in pieces according to any one of claims 2 to 4, characterized in that: Also includes: Generate an error report based on the abnormally written segment file and send it to the server; The error report includes: the file size and fragment number of the fragment file that is written abnormally, the writing time, and the thread name of the thread that executes the writing.

7. A device for uploading large files in pieces, characterized in that: include: The first judgment module is used to judge whether there is a segment file that has been successfully uploaded in the server, and if not, the first writing module is triggered, and if so, the second judgment module is triggered; wherein the segment file is obtained by segmenting a large file into fixed-size segments; The first writing module is used to write data to the corresponding position of the server using the file size of the fragmented file to be uploaded as a fragmentation rule; The second judgment module is used to query the file size of the segmented file successfully uploaded for the first time, and judge whether it is smaller than the file size of the segmented file to be uploaded, if not, trigger the second writing module, if yes, trigger the third writing module; The second writing module is used to write data to a corresponding position of the server by taking the file size of the queried shard file as the sharding rule; The third writing module is used to write data to the corresponding position of the server using the file size of the segmented file to be uploaded as the segmentation rule; after all subsequent threads complete uploading the segmented file, rewrite the queried segmented file as the tail segment to the server; Wherein, according to the sharding rule, writing data to a corresponding position of the server includes: Determine the writing start position according to the product of the sharding rule and the shard number of the current shard file; According to the write start position, the data in the segment file is written to the corresponding position of the server.

8. A device for uploading large files in pieces, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for uploading a large file in pieces as described in any one of claims 1 to 6 when executing the computer program.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the steps of the large file segment uploading method as described in any one of claims 1 to 6 are implemented.