File upload method and system based on distributed object storage
Through multi-part upload and MD5 value verification, combined with breakpoint resumption, the problems of large file upload efficiency and fault tolerance in distributed object storage systems are solved, and efficient and stable file transmission is achieved.
Patent Information
- Application Number
- CN202211244478.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-12
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-10-12
AI Technical Summary
In a distributed object storage system, direct uploading of large files will cause high memory pressure on the business server and high network bandwidth usage. It is also easy to cause upload failure due to network disconnection or other interruptions, reducing user experience and efficiency.
The multi-part upload method is used to ensure file integrity and stability through multi-part upload between the client, business server and object storage system, using MD5 value verification and breakpoint resumption mechanism.
It effectively reduces the memory and network pressure on each node, improves file upload efficiency, enhances system stability and fault tolerance, avoids retries of the entire process, and improves user experience and business execution efficiency.
Smart Images

Figure CN116032913B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of object storage, and in particular to a file uploading method and system based on distributed object storage. Background Art
[0002] At present, more and more business scenarios need to upload large files and use distributed object storage systems. At the same time, most of the upload of large files is related to business and needs to be processed by the business server. It is not applicable to directly upload large files from the client to the distributed object storage system. Therefore, it is necessary to connect the client, business server, and distributed object storage system in series. The traditional processing flow is to upload the complete file together with the corresponding business parameters directly to the business server, and then upload the file to the object storage system after the server performs the corresponding business processing. This will cause considerable memory pressure on the business server. At the same time, uploading large files requires a large amount of customer network bandwidth and connection time. Once an error occurs during the process, such as network disconnection, business logout, customer computer shutdown, etc., the entire upload process will fail and the upload operation can only be re-executed, which greatly reduces the user experience and business execution efficiency. Therefore, it is particularly important to improve the efficiency and fault tolerance of large file uploads without affecting the business execution process.
[0003] How to improve file upload efficiency and reduce fault tolerance is a technical problem that needs to be solved. Summary of the invention
[0004] The technical task of the present invention is to address the above shortcomings and provide a file uploading method and system based on distributed object storage to solve the technical problem of how to improve the file uploading efficiency and reduce the fault tolerance rate.
[0005] In a first aspect, the present invention provides a method for uploading files based on distributed object storage, which implements uploading of the files between a client, a business service end, and an object storage system by uploading in pieces, and the method comprises the following steps:
[0006] For a file to be uploaded, judging whether the file exists in the distributed storage object based on the MD5 value of the file;
[0007] If the file to be uploaded does not exist in the object storage system, upload the file to be uploaded in pieces. For each piece, verify the piece upload between the client and the business server and the piece upload between the business server and the object storage system based on the MD value of the piece. If the piece upload fails, re-upload the piece.
[0008] After all the segments of the file to be uploaded are uploaded to the object storage system, the file upload between the client, the business service end and the object storage system is verified based on the MD value of the file to be uploaded. If the file upload fails, the file to be uploaded is re-uploaded in segments.
[0009] Preferably, for a file to be uploaded, judging whether the file exists in a distributed storage object based on the MD5 value of the file comprises the following steps:
[0010] The client divides the file to be uploaded into multiple fragments, calculates the MD5 value of each fragment, and combines the MD5 values of all fragments as the MD value of the file to be uploaded;
[0011] The client sends the MD5 value of the file to be uploaded and the business parameters to the business server to initialize the multi-slice upload task;
[0012] After receiving the MD5 value of the file to be uploaded and the business parameters, the business server queries whether the file to be uploaded already exists in the object storage system based on the MD5 value of the file to be uploaded;
[0013] If the file to be uploaded already exists in the object storage system, marking the file to be uploaded as uploaded;
[0014] If the file to be uploaded does not exist in the object storage system, the MD5 value of the file to be uploaded and the business parameters are persistently stored through the business server.
[0015] Preferably, if the file to be uploaded does not exist in the object storage system, before allocating and uploading the file to be uploaded, the following operations are performed:
[0016] Send instructions to the object storage system through the business server to initialize the segment upload task and obtain the segment upload task id, which is used as a unique identifier for uploading the segment of the file to be uploaded;
[0017] According to the file segmentation rule, the business server calculates the segment size to form segment information, wherein the segment information includes the segment size of a single segment, the segment size of the last segment, and the number of segments;
[0018] The shard upload task id and the shard information are persistently stored through the business server.
[0019] Preferably, the file to be uploaded is uploaded in pieces by segmenting and uploading the pieces one by one. For each piece, the segmenting and uploading of the pieces includes the following operations:
[0020] L1. Based on the fragment information, the business server calculates the cutting position of the fragment on the file to be uploaded, and sends the fragment upload task ID and the obtained cutting position to the client;
[0021] L2. After receiving the shard upload task ID and the cutting position, the client splits the file to be uploaded based on the cutting position, obtains the current shard and numbers the current shard, calculates the MD5 value of the current shard, and uploads the current shard and its number, the MD5 value of the current shard, and the shard upload task ID to the business server;
[0022] L3. After receiving the current slice and its number, the MD5 value of the current slice, and the slice upload task ID, the business server verifies based on the slice upload task ID and queries whether the current slice has been uploaded in the object storage system. If yes, the current slice is no longer uploaded. If not, the next step is executed.
[0023] L4. According to the shard upload task ID and shard information, check whether the current shard is the last shard and calculate the size of the current shard. Compare the size of the current shard with the size of the current shard received. If the size values are inconsistent, return an error prompt to the client and ask the client to re-upload the current shard. If the sizes are consistent, proceed to the next step.
[0024] L5. The business server calculates the MD5 value of the current shard, and compares the calculated MD5 value of the current shard with the received MD5 value of the current shard. If they are inconsistent, an error prompt is returned to the client, requiring the client to re-upload the current shard. If they are consistent, the next step is executed;
[0025] L6. The business server uploads the current shard and its number to the object storage system, and compares the MD5 value of the current shard with the eTag value of the current shard returned from the object storage system. If they are inconsistent, the business server re-uploads the current shard. If they are consistent, proceed to the next step.
[0026] After receiving the current shard uploaded by the business server, the object storage system calculates the MD5 of the current shard as the eTag value of the current shard, and returns the eTag value of the current shard to the business server;
[0027] L7. The business service system determines whether the current fragment is the last fragment according to the fragment information. If not, execute step L8. If yes, execute the following operations:
[0028] Based on the shard upload task ID, query the eTag values of all shards from the business server, and combine the eTag values of all shards as the eTag value of the file to be uploaded;
[0029] The calculated eTag value of the file to be uploaded is compared with the queried eTag of the file to be uploaded. If they are consistent, the file to be uploaded is uploaded successfully. If they are inconsistent, the file to be uploaded is uploaded again in pieces;
[0030] L8, persist the MD5 value of the current shard, calculate the cutting position of the next shard by executing steps L1-L7 and upload the next shard;
[0031] When the client and the business server re-upload the current shard, the historical data generated by the corresponding shard upload operation will be overwritten based on the number of the current shard;
[0032] When re-uploading the uploaded file, the historical data formed by the corresponding multi-segment upload operation will be overwritten based on the multi-segment upload task id.
[0033] As a preferred method, when an interruption occurs during the uploading of a segment, the current segment is resumable;
[0034] The breakpoint resume includes the following steps:
[0035] M1. For the file to be uploaded, the client sends a breakpoint resume request to the business server, where the breakpoint resume request includes the MD5 value of the file and the segment upload task ID;
[0036] M2. After receiving the breakpoint resume request, the business server queries the MD5 value of the original file in persistent storage based on the shard upload task ID, and compares it with the MD5 value of the file sent by the client. If they are inconsistent, an error prompt is returned to the client, requiring the client to reselect the file to upload. If they are consistent, M3 is executed;
[0037] M3. Query the number of uploaded shards in the object storage system according to the shard upload task ID. Based on the number of uploaded shards and the shard information stored persistently, perform the shard upload operation on the next shard until all shards are uploaded.
[0038] In a second aspect, the present invention provides a file upload system based on distributed object storage, including a client, a business server, and an object storage system, wherein the client, the business server, and the object storage system cooperate to implement file upload between the client, the business server, and the object storage system by using the method described in any one of the first aspects;
[0039] For a file to be uploaded, the client, the business server and the object storage system cooperate to determine whether the file exists in the distributed storage object based on the MD5 value of the file;
[0040] If the file to be uploaded does not exist in the object storage system, the client, the business server and the object storage system cooperate to perform: uploading the file to be uploaded in pieces, for each piece, verifying the piece upload between the client and the business server and the piece upload between the business server and the object storage system based on the MD value of the piece, and if the piece upload fails, re-uploading the piece;
[0041] After all the segments of the file to be uploaded are uploaded to the object storage system, the client, the business server and the object storage system cooperate to perform: verifying the file upload between the client, the business server and the object storage system based on the MD value of the file to be uploaded; if the file upload fails, re-uploading the file to be uploaded in segments.
[0042] Preferably, for the file to be uploaded, the client is used to execute: dividing the file to be uploaded into multiple fragments, calculating the MD5 value of each fragment, combining the MD5 values of all fragments as the MD value of the file to be uploaded, and sending the MD5 value of the file to be uploaded and the business parameters to the business server to initialize the fragment upload task;
[0043] Correspondingly, the business server is used to execute:
[0044] After receiving the MD5 value of the file to be uploaded and the service parameters, querying whether the file to be uploaded already exists in the object storage system based on the MD5 value of the file to be uploaded;
[0045] If the file to be uploaded already exists in the object storage system, marking the file to be uploaded as uploaded;
[0046] If the file to be uploaded does not exist in the object storage system, the MD5 value of the file to be uploaded and the business parameters are persistently stored.
[0047] Preferably, if the file to be uploaded does not exist in the object storage system, before uploading the file to be uploaded in pieces, the business server is used to execute:
[0048] Send an instruction to the object storage system to initialize the segment upload task and obtain the segment upload task ID, which is used as a unique identifier for uploading the segment of the file to be uploaded;
[0049] Calculating the fragment size according to the file segmentation rule to form fragment information, wherein the fragment information includes the fragment size of a single fragment, the fragment size of the last fragment, and the number of fragments;
[0050] The shard upload task id and the shard information are persistently stored.
[0051] Preferably, the client, the business server and the object storage system cooperate to upload the file to be uploaded in pieces by segmenting and uploading the pieces one by one. For the segmentation and uploading of each piece, the client, the business server and the object storage system are used to perform the following:
[0052] L1. The business server calculates the cutting position of the slice on the file to be uploaded based on the slice information, and sends the slice upload task ID and the obtained cutting position to the client;
[0053] L2. After receiving the shard upload task ID and the cutting position, the client splits the file to be uploaded based on the cutting position, obtains the current shard and numbers the current shard, calculates the MD5 value of the current shard, and uploads the current shard and its number, the MD5 value of the current shard, and the shard upload task ID to the business server;
[0054] L3. After receiving the current slice and its number, the MD5 value of the current slice, and the slice upload task ID, the business server verifies based on the slice upload task ID and queries whether the current slice has been uploaded in the object storage system. If yes, the current slice is no longer uploaded. If not, the next step is executed.
[0055] L4. According to the shard upload task ID and shard information, check whether the current shard is the last shard and calculate the size of the current shard. Compare the size of the current shard with the size of the current shard received. If the size values are inconsistent, return an error prompt to the client and ask the client to re-upload the current shard. If the sizes are consistent, proceed to the next step.
[0056] L5. The business server calculates the MD5 value of the current shard, and compares the calculated MD5 value of the current shard with the received MD5 value of the current shard. If they are inconsistent, an error prompt is returned to the client, requiring the client to re-upload the current shard. If they are consistent, the next step is executed;
[0057] L6. The business server uploads the current shard and its number to the object storage system, and compares the MD5 value of the current shard with the eTag value of the current shard returned from the object storage system. If they are inconsistent, the business server re-uploads the current shard. If they are consistent, proceed to the next step.
[0058] After receiving the current shard uploaded by the business server, the object storage system calculates the MD5 of the current shard as the eTag value of the current shard, and returns the eTag value of the current shard to the business server;
[0059] L7. The business service system determines whether the current fragment is the last fragment according to the fragment information. If not, execute step L8. If yes, execute the following operations:
[0060] Based on the shard upload task ID, query the eTag values of all shards from the business server, and combine the eTag values of all shards as the eTag value of the file to be uploaded;
[0061] The calculated eTag value of the file to be uploaded is compared with the queried eTag of the file to be uploaded. If they are consistent, the file to be uploaded is uploaded successfully. If they are inconsistent, the file to be uploaded is uploaded again in pieces;
[0062] L8, persist the MD5 value of the current shard, calculate the cutting position of the next shard by executing steps L1-L7 and upload the next shard;
[0063] When the client and the business server re-upload the current shard, the historical data generated by the corresponding shard upload operation will be overwritten based on the number of the current shard;
[0064] When re-uploading the uploaded file, the historical data formed by the corresponding multi-segment upload operation will be overwritten based on the multi-segment upload task id.
[0065] Preferably, when an interruption occurs during the uploading of a segment, the client, the business server, and the object storage system cooperate to resume the uploading of the current segment through the following operations:
[0066] M1. For the file to be uploaded, the client sends a breakpoint resume request to the business server, where the breakpoint resume request includes the MD5 value of the file and the segment upload task ID;
[0067] M2. After receiving the breakpoint resume request, the business server queries the MD5 value of the original file in persistent storage based on the shard upload task ID, and compares it with the MD5 value of the file sent by the client. If they are inconsistent, an error prompt is returned to the client, requiring the client to reselect the file to upload. If they are consistent, M3 is executed;
[0068] M3. Query the number of uploaded shards in the object storage system according to the shard upload task ID. Based on the number of uploaded shards and the shard information stored persistently, perform the shard upload operation on the next shard until all shards are uploaded.
[0069] The file uploading method and system based on distributed object storage of the present invention have the following advantages:
[0070] 1. Use the fragmented upload method to connect the client, business server, and distributed object storage system in series, which can effectively reduce the memory and network pressure of each node and improve system stability;
[0071] 2. Upload files in pieces and verify the integrity of the upload process through the MD5 value of each piece, so that errors can be found and retried in time to improve efficiency;
[0072] 3. Providing breakpoint resume can greatly improve the system's fault tolerance, avoid retrying the entire process, and thus improve efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0074] The present invention is further described below in conjunction with the accompanying drawings.
[0075] Figure 1 This is a flowchart of the file upload method based on distributed object storage in Example 1. DETAILED DESCRIPTION
[0076] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
[0077] The embodiment of the present invention provides a file upload system based on distributed object storage, which is used to solve the technical problem.
[0078] Embodiment 1:
[0079] The present invention discloses a file uploading method based on distributed object storage, which realizes uploading of the file between a client, a business service end and an object storage system by uploading in pieces.
[0080] The method comprises the following steps:
[0081] Step S100: for a file to be uploaded, determine whether the file exists in a distributed storage object based on the MD5 value of the file.
[0082] As a specific implementation of step S100, for a file to be uploaded, judging whether the file exists in a distributed storage object based on the MD5 value of the file includes the following steps:
[0083] Step S110: The client divides the file to be uploaded into multiple fragments, calculates the MD5 value of each fragment, and combines the MD5 values of all fragments as the MD5 value of the file to be uploaded;
[0084] Step S120: Send the MD5 value of the file to be uploaded and the service parameters to the service server through the client to initialize the segment upload task;
[0085] Step S130: After receiving the MD5 value of the file to be uploaded and the service parameters, the service server queries whether the file to be uploaded already exists in the object storage system based on the MD5 value of the file to be uploaded;
[0086] Step S140: If the file to be uploaded already exists in the object storage system, mark the file to be uploaded as uploaded;
[0087] If the file to be uploaded does not exist in the object storage system, the MD5 value of the file to be uploaded and the business parameters are persistently stored through the business server.
[0088] Based on the above specific process, when a user chooses to upload a large file (i.e. the file size exceeds a certain limit, the default configuration is 5M), the client (program, browser, app, etc.) performs preprocessing, including calculating the MD5 value of the large file and integrating other business parameters.
[0089] When calculating the MD5 value of a large file, due to computer performance limitations, when the file is too large, the MD5 value calculation speed will be greatly reduced and it will take up a lot of computer memory. Therefore, a fragmented method is used to divide the file into several pieces, calculate the MD5 value separately, and finally combine them.
[0090] After the above steps are completed, the file MD5 value and other business parameters are sent to the business server to initialize the multi-slice upload task.
[0091] When the business server receives the parameters sent by the client, it will first query the file object storage system based on the MD5 value to see if there is a file with the same name (using the MD5 value as the file name and as the unique identifier of the file). If it exists, it indicates that the file has been successfully uploaded before, and the subsequent upload steps will not be executed. The relevant business processing steps will be executed directly, and after completion, it will return to the client that the upload is completed, that is, "instant upload"; if it does not exist, the relevant parameters will be persisted (that is, stored in a database or other persistence tool) so that relevant business processing can be performed after the upload is completed.
[0092] Step S200: If the file to be uploaded does not exist in the object storage system, upload the file to be uploaded in pieces.
[0093] When uploading the file to be uploaded in pieces, the following is performed:
[0094] (1) For each shard, verify the shard upload between the client and the business server and the shard upload between the business server and the object storage system based on the MD5 value of the shard. If the shard upload fails, re-upload the shard;
[0095] (2) After all the segments of the file to be uploaded are uploaded to the object storage system, the file upload between the client, the business server and the object storage system is verified based on the MD5 value of the file. If the file upload fails, the file to be uploaded is re-uploaded in segments;
[0096] (3) When an interruption occurs during the uploading of a segment, the current segment is resumed from the breakpoint.
[0097] As a specific implementation of step S200, if the file to be uploaded does not exist in the object storage system, first, an instruction is sent to the object storage system through the business server to initialize the segmented upload task, and the segmented upload task id, i.e., upload_id, is obtained, which is a unique identifier of the large file segmented upload task and is used for segmented upload, segment query, breakpoint resume, etc.; then, according to the file segmentation rule, the segment size is calculated by the business server to form segment information, and the segment information includes the segment size of a single segment, the segment size of the last segment, and the number of segments; finally, the segmented upload task id and the segment information are persistently stored through the business server so that the corresponding information can be retrieved when the subsequent segments are uploaded.
[0098] The uploaded file is split equally, that is, the size of each fragment is the same. Considering the specific requirements of the file size and the number of fragments, the size of the last fragment may be inconsistent with the sizes of other fragments. Therefore, it is necessary to calculate the fragment size of a single fragment and the fragment size of the last fragment.
[0099] After performing the above operations, the file to be uploaded is uploaded in pieces by segmenting and uploading the pieces one by one. For each piece, the segmentation and uploading of the pieces includes the following operations:
[0100] L1. Based on the fragment information, the business server calculates the cutting position of the fragment on the file to be uploaded, and sends the fragment upload task ID and the obtained cutting position to the client;
[0101] L2. After receiving the shard upload task ID and the cutting position, the client splits the file to be uploaded based on the cutting position, obtains the current shard and numbers the current shard, calculates the MD5 value of the current shard, and uploads the current shard and its number, the MD5 value of the current shard, and the shard upload task ID to the business server;
[0102] L3. After receiving the current slice and its number, the MD5 value of the current slice, and the slice upload task ID, the business server verifies based on the slice upload task ID and queries whether the current slice has been uploaded in the object storage system. If yes, it means that the slice upload task has been completed or does not exist, and the current slice will not be uploaded. If not, proceed to the next step.
[0103] L4. According to the shard upload task ID and shard information, check whether the current shard is the last shard and calculate the size of the current shard. Compare the size of the current shard with the size of the current shard received. If the size values are inconsistent, it means that the client has made an error in cutting the file or there is data loss during data transmission. No further steps are performed and an error prompt is returned to the client. The client is required to re-upload the current shard. If the sizes are consistent, proceed to the next step.
[0104] L5. The business server calculates the MD5 value of the current shard, and compares the calculated MD5 value of the current shard with the received MD5 value of the current shard. If they are inconsistent, it means that the client calculated the MD5 value of the shard incorrectly or the file was damaged during transmission. The subsequent steps are no longer performed, and an error prompt is returned to the client, requiring the client to re-upload the current shard. If they are consistent, the next step is performed;
[0105] L6. The business server uploads the current shard and its number to the object storage system, and compares the MD5 value of the current shard with the eTag value of the current shard returned from the object storage system. If they are inconsistent, it means that the file is damaged during the transmission process. The business server re-uploads the current shard. If they are consistent, it means that the transmission process is correct and the next step is executed.
[0106] After receiving the current shard uploaded by the business server, the object storage system calculates the MD5 of the current shard as the eTag value of the current shard, and returns the eTag value of the current shard to the business server;
[0107] L7. The business service system determines whether the current fragment is the last fragment according to the fragment information. If not, execute step L8. If yes, execute the following operations:
[0108] Based on the shard upload task ID, query the eTag values of all shards from the business server, and combine the eTag values of all shards as the eTag value of the file to be uploaded;
[0109] The calculated eTag value of the file to be uploaded is compared with the queried eTag of the file to be uploaded. If they are consistent, the file to be uploaded is uploaded successfully. If they are inconsistent, the file to be uploaded is uploaded again in pieces;
[0110] L8. Persist the MD5 value of the current shard, calculate the cutting position of the next shard by executing steps L1-L7, and upload the next shard.
[0111] In this embodiment, when the client and the service server re-upload the current segment, the historical data formed by the corresponding segment upload operation is overwritten based on the number of the current segment.
[0112] When re-uploading the uploaded file, the historical data formed by the corresponding multi-segment upload operation will be overwritten based on the multi-segment upload task id.
[0113] If an interruption occurs during the upload process, such as the client exiting or restarting, the network disconnecting, or the business server restarting, the client will perform breakpoint-resume operations.
[0114] In this embodiment, breakpoint resuming includes the following steps:
[0115] M1. For the file to be uploaded, the client sends a breakpoint resume request to the business server, where the breakpoint resume request includes the MD5 value of the file and the segment upload task ID;
[0116] M2. After receiving the breakpoint resume request, the business server queries the MD5 value of the original file in persistent storage based on the shard upload task ID, and compares it with the MD5 value of the file sent by the client. If they are inconsistent, an error prompt is returned to the client, requiring the client to reselect the file to upload. If they are consistent, M3 is executed;
[0117] M3. Query the number of uploaded shards in the object storage system according to the shard upload task ID. Based on the number of uploaded shards and the shard information stored persistently, perform the shard upload operation on the next shard until all shards are uploaded.
[0118] After the file is uploaded, the business server retrieves the business-related data stored in the persistence tool and performs business processing. At this point, the large file upload is completed.
[0119] Embodiment 2:
[0120] The present invention provides a file upload system based on distributed object storage, including a client, a business server and an object storage system. The client, the business server and the object storage system cooperate to realize file upload between the client, the business server and the object storage system through the method disclosed in Example 1.
[0121] For a file to be uploaded, the client, the business server and the object storage system cooperate to determine whether the file exists in the distributed storage object based on the MD5 value of the file.
[0122] As a specific implementation, for the file to be uploaded, the client is used to execute: dividing the file to be uploaded into multiple segments, calculating the MD5 value of each segment, and combining the MD5 values of all segments as the MD value of the file to be uploaded, and sending the MD5 value of the file to be uploaded and the business parameters to the business server to initialize the segment upload task.
[0123] Correspondingly, the business service end is used to execute: after receiving the MD5 value and business parameters of the file to be uploaded, query whether the file to be uploaded already exists in the object storage system based on the MD5 value of the file to be uploaded; if the file to be uploaded already exists in the object storage system, mark the file to be uploaded as uploaded; if the file to be uploaded does not exist in the object storage system, persistently store the MD5 value and business parameters of the file to be uploaded.
[0124] During the application of this system, when the user chooses to upload a large file (that is, the file size exceeds a certain limit, the default configuration is 5M), the client (program, browser, app, etc.) performs preprocessing, including calculating the MD5 value of the large file and integrating other business parameters.
[0125] When calculating the MD5 value of a large file, due to computer performance limitations, when the file is too large, the MD5 value calculation speed will be greatly reduced and it will take up a lot of computer memory. Therefore, a fragmented method is used to divide the file into several pieces, calculate the MD5 value separately, and finally combine them.
[0126] When the business server receives the parameters sent by the client, it will first query the file object storage system based on the MD5 value to see if there is a file with the same name (using the MD5 value as the file name and as the unique identifier of the file). If it exists, it indicates that the file has been successfully uploaded before, and the subsequent upload steps will not be executed. The relevant business processing steps will be executed directly, and after completion, it will return to the client that the upload is completed, that is, "instant upload"; if it does not exist, the relevant parameters will be persisted (that is, stored in a database or other persistence tool) so that relevant business processing can be performed after the upload is completed.
[0127] If the file to be uploaded does not exist in the object storage system, the client, the service server and the object storage system cooperate to upload the file to be uploaded in pieces. When uploading the file to be uploaded in pieces, the client, the service server and the object storage system cooperate to perform the following:
[0128] (1) For each shard, verify the shard upload between the client and the business server and the shard upload between the business server and the object storage system based on the MD5 value of the shard. If the shard upload fails, re-upload the shard;
[0129] (2) After all the segments of the file to be uploaded are uploaded to the object storage system, the file upload between the client, the business server and the object storage system is verified based on the MD5 value of the file. If the file upload fails, the file to be uploaded is re-uploaded in segments;
[0130] (3) When an interruption occurs during the uploading of a segment, the current segment is resumed from the breakpoint.
[0131] As a specific implementation, if the file to be uploaded does not exist in the object storage system, before uploading the file to be uploaded in pieces, the business server is used to execute:
[0132] (1) Sending an instruction to the object storage system to initialize the segment upload task and obtaining the segment upload task ID, where the segment upload task ID is used as a unique identifier for uploading the segment of the file to be uploaded;
[0133] (2) calculating the fragment size according to the file segmentation rule to form fragment information, wherein the fragment information includes the fragment size of a single fragment, the fragment size of the last fragment, and the number of fragments;
[0134] (3) The shard upload task ID and the shard information are persistently stored.
[0135] The uploaded file is split equally, that is, the size of each fragment is the same. Considering the specific requirements of the file size and the number of fragments, the size of the last fragment may be inconsistent with the sizes of other fragments. Therefore, it is necessary to calculate the fragment size of a single fragment and the fragment size of the last fragment.
[0136] In this embodiment, the client, the business server, and the object storage system cooperate to upload the file to be uploaded in pieces by segmenting and uploading the pieces one by one. For the segmentation and uploading of each piece, the client, the business server, and the object storage system are used to perform the following:
[0137] L1. The business server calculates the cutting position of the slice on the file to be uploaded based on the slice information, and sends the slice upload task ID and the obtained cutting position to the client;
[0138] L2. After receiving the shard upload task ID and the cutting position, the client splits the file to be uploaded based on the cutting position, obtains the current shard and numbers the current shard, calculates the MD5 value of the current shard, and uploads the current shard and its number, the MD5 value of the current shard, and the shard upload task ID to the business server;
[0139] L3. After receiving the current slice and its number, the MD5 value of the current slice, and the slice upload task ID, the business server verifies based on the slice upload task ID and queries whether the current slice has been uploaded in the object storage system. If yes, the current slice is no longer uploaded. If not, the next step is executed.
[0140] L4. According to the shard upload task ID and shard information, check whether the current shard is the last shard and calculate the size of the current shard. Compare the size of the current shard with the size of the current shard received. If the size values are inconsistent, return an error prompt to the client and ask the client to re-upload the current shard. If the sizes are consistent, proceed to the next step.
[0141] L5. The business server calculates the MD5 value of the current shard, and compares the calculated MD5 value of the current shard with the received MD5 value of the current shard. If they are inconsistent, an error prompt is returned to the client, requiring the client to re-upload the current shard. If they are consistent, the next step is executed;
[0142] L6. The business server uploads the current shard and its number to the object storage system, and compares the MD5 value of the current shard with the eTag value of the current shard returned from the object storage system. If they are inconsistent, the business server re-uploads the current shard. If they are consistent, proceed to the next step.
[0143] After receiving the current shard uploaded by the business server, the object storage system calculates the MD5 of the current shard as the eTag value of the current shard, and returns the eTag value of the current shard to the business server;
[0144] L7. The business service system determines whether the current fragment is the last fragment according to the fragment information. If not, execute step L8. If yes, execute the following operations:
[0145] Based on the shard upload task ID, query the eTag values of all shards from the business server, and combine the eTag values of all shards as the eTag value of the file to be uploaded;
[0146] The calculated eTag value of the file to be uploaded is compared with the queried eTag of the file to be uploaded. If they are consistent, the file to be uploaded is uploaded successfully. If they are inconsistent, the file to be uploaded is uploaded again in pieces;
[0147] L8, persist the MD5 value of the current shard, calculate the cutting position of the next shard by executing steps L1-L7 and upload the next shard;
[0148] When the client and the business server re-upload the current shard, the historical data generated by the corresponding shard upload operation will be overwritten based on the number of the current shard;
[0149] When re-uploading the uploaded file, the historical data formed by the corresponding multi-segment upload operation will be overwritten based on the multi-segment upload task id.
[0150] The client, business server, and object storage system work together to resume the current shard through the following operations:
[0151] M1. For the file to be uploaded, the client sends a breakpoint resume request to the business server, where the breakpoint resume request includes the MD5 value of the file and the segment upload task ID;
[0152] M2. After receiving the breakpoint resume request, the business server queries the MD5 value of the original file in persistent storage based on the shard upload task ID, and compares it with the MD5 value of the file sent by the client. If they are inconsistent, an error prompt is returned to the client, requiring the client to reselect the file to upload. If they are consistent, M3 is executed;
[0153] M3. Query the number of uploaded shards in the object storage system according to the shard upload task ID. Based on the number of uploaded shards and the shard information stored persistently, perform the shard upload operation on the next shard until all shards are uploaded.
[0154] The present invention is shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.
Claims
1. A file upload method based on distributed object storage, characterized in that: The method for uploading the file between the client, the business server and the object storage system by uploading the file in pieces includes the following steps: For a file to be uploaded, judging whether the file exists in the distributed storage object based on the MD5 value of the file; If the file to be uploaded does not exist in the object storage system, uploading the file to be uploaded in pieces; When uploading the file to be uploaded in pieces, execute as follows: For each shard, verify the shard upload between the client and the business server and the shard upload between the business server and the object storage system based on the MD5 value of the shard. If the shard upload fails, re-upload the shard. After all the segments of the file to be uploaded are uploaded to the object storage system, the file upload between the client, the business server and the object storage system is verified based on the MD5 value of the file. If the file upload fails, the file to be uploaded is re-uploaded in segments; When an interruption occurs during the segment upload process, the current segment is resumed from the breakpoint. For a file to be uploaded, judging whether the file exists in a distributed storage object based on the MD5 value of the file includes the following steps: The client divides the file to be uploaded into multiple fragments, calculates the MD5 value of each fragment, and combines the MD5 values of all fragments as the MD value of the file to be uploaded; The client sends the MD5 value of the file to be uploaded and the business parameters to the business server to initialize the multi-slice upload task; After receiving the MD5 value of the file to be uploaded and the business parameters, the business server queries whether the file to be uploaded already exists in the object storage system based on the MD5 value of the file to be uploaded; If the file to be uploaded already exists in the object storage system, marking the file to be uploaded as uploaded; If the file to be uploaded does not exist in the object storage system, the MD5 value of the file to be uploaded and the business parameters are persistently stored through the business server; If the file to be uploaded does not exist in the object storage system, before allocating and uploading the file to be uploaded, perform the following operations: Send instructions to the object storage system through the business server to initialize the segment upload task and obtain the segment upload task id, which is used as the unique identifier for uploading the segment of the file to be uploaded; According to the file segmentation rule, the business server calculates the segment size to form segment information, wherein the segment information includes the segment size of a single segment, the segment size of the last segment, and the number of segments; The shard upload task id and the shard information are persistently stored through the business server; The file to be uploaded is uploaded in pieces by segmenting and uploading the pieces one by one. For each piece, the segmentation and uploading of the pieces includes the following operations: L1. Based on the fragment information, the business server calculates the cutting position of the fragment on the file to be uploaded, and sends the fragment upload task ID and the obtained cutting position to the client; L2. After receiving the shard upload task ID and the cutting position, the client splits the file to be uploaded based on the cutting position, obtains the current shard and numbers the current shard, calculates the MD5 value of the current shard, and uploads the current shard and its number, the MD5 value of the current shard, and the shard upload task ID to the business server; L3. After receiving the current slice and its number, the MD5 value of the current slice, and the slice upload task ID, the business server verifies based on the slice upload task ID and queries whether the current slice has been uploaded in the object storage system. If yes, the current slice is no longer uploaded. If not, the next step is executed. L4. According to the shard upload task ID and shard information, check whether the current shard is the last shard and calculate the size of the current shard. Compare the size of the current shard with the size of the current shard received. If the size values are inconsistent, return an error prompt to the client and ask the client to re-upload the current shard. If the sizes are consistent, proceed to the next step. L5. The business server calculates the MD5 value of the current shard, and compares the calculated MD5 value of the current shard with the received MD5 value of the current shard. If they are inconsistent, an error prompt is returned to the client, requiring the client to re-upload the current shard. If they are consistent, the next step is executed; L6. The business server uploads the current shard and its number to the object storage system, and compares the MD5 value of the current shard with the eTag value of the current shard returned from the object storage system. If they are inconsistent, the business server re-uploads the current shard. If they are consistent, proceed to the next step. After receiving the current shard uploaded by the business server, the object storage system calculates the MD5 of the current shard as the eTag value of the current shard, and returns the eTag value of the current shard to the business server; L7. The business service system determines whether the current fragment is the last fragment according to the fragment information. If not, execute step L8. If yes, execute the following operations: Based on the shard upload task ID, query the eTag values of all shards from the business server, and combine the eTag values of all shards as the eTag value of the file to be uploaded; The calculated eTag value of the file to be uploaded is compared with the queried eTag of the file to be uploaded. If they are consistent, the file to be uploaded is uploaded successfully. If they are inconsistent, the file to be uploaded is uploaded again in pieces; L8, persist the MD5 value of the current shard, calculate the cutting position of the next shard by executing steps L1-L7 and upload the next shard; When the client and the business server re-upload the current shard, the historical data generated by the corresponding shard upload operation will be overwritten based on the number of the current shard; When re-uploading a file, the historical data generated by the corresponding segment upload operation will be overwritten based on the segment upload task id; The breakpoint resume includes the following steps: M1. For the file to be uploaded, the client sends a breakpoint resume request to the business server, where the breakpoint resume request includes the MD5 value of the file and the segment upload task ID; M2. After receiving the breakpoint resume request, the business server queries the MD5 value of the original file in persistent storage based on the shard upload task ID, and compares it with the MD5 value of the file sent by the client. If they are inconsistent, an error prompt is returned to the client, requiring the client to reselect the file to upload. If they are consistent, M3 is executed; M3. Query the number of uploaded shards in the object storage system according to the shard upload task ID. Based on the number of uploaded shards and the shard information stored persistently, perform the shard upload operation on the next shard until all shards are uploaded.
2. A file upload system based on distributed object storage, characterized in that: The method comprises a client, a business server and an object storage system, wherein the client, the business server and the object storage system cooperate to upload files between the client, the business server and the object storage system through the method according to claim 1; For a file to be uploaded, the client, the business server and the object storage system cooperate to determine whether the file exists in the distributed storage object based on the MD5 value of the file; If the file to be uploaded does not exist in the object storage system, the client, the business server and the object storage system cooperate to upload the file to be uploaded in pieces; When uploading the file to be uploaded in pieces, the client, the business server and the object storage system cooperate to perform the following: For each shard, verify the shard upload between the client and the business server and the shard upload between the business server and the object storage system based on the MD5 value of the shard. If the shard upload fails, re-upload the shard. After all the segments of the file to be uploaded are uploaded to the object storage system, the file upload between the client, the business server and the object storage system is verified based on the MD5 value of the file. If the file upload fails, the file to be uploaded is re-uploaded in segments; When an interruption occurs during the segment upload process, the current segment is resumed from the breakpoint. For the file to be uploaded, the client is used to execute: split the file to be uploaded into multiple fragments, calculate the MD5 value of each fragment, and combine the MD5 values of all fragments as the MD value of the file to be uploaded, and send the MD5 value of the file to be uploaded and the business parameters to the business server to initialize the fragment upload task; Correspondingly, the business server is used to execute: After receiving the MD5 value of the file to be uploaded and the service parameters, querying whether the file to be uploaded already exists in the object storage system based on the MD5 value of the file to be uploaded; If the file to be uploaded already exists in the object storage system, marking the file to be uploaded as uploaded; If the file to be uploaded does not exist in the object storage system, the MD5 value of the file to be uploaded and the business parameters are persistently stored; If the file to be uploaded does not exist in the object storage system, before uploading the file to be uploaded in pieces, the business server is used to execute: Send an instruction to the object storage system to initialize the segment upload task and obtain the segment upload task ID, which is used as a unique identifier for uploading the segment of the file to be uploaded; Calculating the fragment size according to the file segmentation rule to form fragment information, wherein the fragment information includes the fragment size of a single fragment, the fragment size of the last fragment, and the number of fragments; Persistently storing the shard upload task id and the shard information; The client, the business server and the object storage system cooperate to upload the file to be uploaded in pieces by segmenting and uploading the pieces one by one. For the segmentation and uploading of each piece, the client, the business server and the object storage system are used to perform the following: L1. The business server calculates the cutting position of the slice on the file to be uploaded based on the slice information, and sends the slice upload task ID and the obtained cutting position to the client; L2. After receiving the shard upload task ID and the cutting position, the client splits the file to be uploaded based on the cutting position, obtains the current shard and numbers the current shard, calculates the MD5 value of the current shard, and uploads the current shard and its number, the MD5 value of the current shard, and the shard upload task ID to the business server; L3. After receiving the current slice and its number, the MD5 value of the current slice, and the slice upload task ID, the business server verifies based on the slice upload task ID and queries whether the current slice has been uploaded in the object storage system. If yes, the current slice is no longer uploaded. If not, the next step is executed. L4. According to the shard upload task ID and shard information, check whether the current shard is the last shard and calculate the size of the current shard. Compare the size of the current shard with the size of the current shard received. If the size values are inconsistent, return an error prompt to the client and ask the client to re-upload the current shard. If the sizes are consistent, proceed to the next step. L5. The business server calculates the MD5 value of the current shard, and compares the calculated MD5 value of the current shard with the received MD5 value of the current shard. If they are inconsistent, an error prompt is returned to the client, requiring the client to re-upload the current shard. If they are consistent, the next step is executed; L6. The business server uploads the current shard and its number to the object storage system, and compares the MD5 value of the current shard with the eTag value of the current shard returned from the object storage system. If they are inconsistent, the business server re-uploads the current shard. If they are consistent, proceed to the next step. After receiving the current shard uploaded by the business server, the object storage system calculates the MD5 of the current shard as the eTag value of the current shard, and returns the eTag value of the current shard to the business server; L7. The business service system determines whether the current fragment is the last fragment according to the fragment information. If not, execute step L8. If yes, execute the following operations: Based on the shard upload task ID, query the eTag values of all shards from the business server, and combine the eTag values of all shards as the eTag value of the file to be uploaded; The calculated eTag value of the file to be uploaded is compared with the queried eTag of the file to be uploaded. If they are consistent, the file to be uploaded is uploaded successfully. If they are inconsistent, the file to be uploaded is uploaded again in pieces; L8, persist the MD5 value of the current shard, calculate the cutting position of the next shard by executing steps L1-L7 and upload the next shard; When the client and the business server re-upload the current shard, the historical data generated by the corresponding shard upload operation will be overwritten based on the number of the current shard; When re-uploading a file, the historical data generated by the corresponding segment upload operation will be overwritten based on the segment upload task id; The client, the business server and the object storage system cooperate to resume the current shard through the following operations: M1. For the file to be uploaded, the client sends a breakpoint resume request to the business server, where the breakpoint resume request includes the MD5 value of the file and the segment upload task ID; M2. After receiving the breakpoint resume request, the business server queries the MD5 value of the original file in persistent storage based on the shard upload task ID, and compares it with the MD5 value of the file sent by the client. If they are inconsistent, an error prompt is returned to the client, requiring the client to reselect the file to upload. If they are consistent, M3 is executed; M3. Query the number of uploaded shards in the object storage system according to the shard upload task ID. Based on the number of uploaded shards and the shard information stored persistently, perform the shard upload operation on the next shard until all shards are uploaded.
