Skip to content

Commit 1b63dca

Browse files
committed
fix the bug of uploading big files larger than 100G which caused the blockIndex overflow its type
1 parent 343414e commit 1b63dca

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/Qiniu/Storage/ResumableUploader.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public HttpResult UploadStream(Stream stream, string key, string upToken, PutExt
108108
{
109109
long uploadedBytes = 0;
110110
long fileSize = stream.Length;
111-
int blockCount = (int)((fileSize + BLOCK_SIZE - 1) / BLOCK_SIZE);
111+
long blockCount = (fileSize + BLOCK_SIZE - 1) / BLOCK_SIZE;
112112

113113
//check resume record file
114114
ResumeInfo resumeInfo = null;
@@ -136,7 +136,7 @@ public HttpResult UploadStream(Stream stream, string key, string upToken, PutExt
136136
}
137137

138138
//calc upload progress
139-
for (int blockIndex = 0; blockIndex < blockCount; blockIndex++)
139+
for (long blockIndex = 0; blockIndex < blockCount; blockIndex++)
140140
{
141141
string context = resumeInfo.Contexts[blockIndex];
142142
if (!string.IsNullOrEmpty(context))
@@ -152,16 +152,16 @@ public HttpResult UploadStream(Stream stream, string key, string upToken, PutExt
152152
//check not finished blocks to upload
153153
UploadControllerAction upCtrl = putExtra.UploadController();
154154
ManualResetEvent manualResetEvent = new ManualResetEvent(false);
155-
Dictionary<int, byte[]> blockDataDict = new Dictionary<int, byte[]>();
156-
Dictionary<int, HttpResult> blockMakeResults = new Dictionary<int, HttpResult>();
155+
Dictionary<long, byte[]> blockDataDict = new Dictionary<long, byte[]>();
156+
Dictionary<long, HttpResult> blockMakeResults = new Dictionary<long, HttpResult>();
157157
Dictionary<string, long> uploadedBytesDict = new Dictionary<string, long>();
158158
uploadedBytesDict.Add("UploadProgress", uploadedBytes);
159159
byte[] blockBuffer = new byte[BLOCK_SIZE];
160-
for (int blockIndex = 0; blockIndex < blockCount; blockIndex++)
160+
for (long blockIndex = 0; blockIndex < blockCount; blockIndex++)
161161
{
162162
string context = resumeInfo.Contexts[blockIndex];
163163
if (string.IsNullOrEmpty(context))
164-
{
164+
{
165165
//check upload controller action before each chunk
166166
while (true)
167167
{
@@ -200,7 +200,7 @@ public HttpResult UploadStream(Stream stream, string key, string upToken, PutExt
200200
{
201201
processMakeBlocks(blockDataDict, upToken, putExtra, resumeInfo, blockMakeResults, uploadedBytesDict, fileSize);
202202
//check mkblk results
203-
foreach(int blkIndex in blockMakeResults.Keys)
203+
foreach (int blkIndex in blockMakeResults.Keys)
204204
{
205205
HttpResult mkblkRet = blockMakeResults[blkIndex];
206206
if (mkblkRet.Code != 200)
@@ -292,15 +292,15 @@ public HttpResult UploadStream(Stream stream, string key, string upToken, PutExt
292292
return result;
293293
}
294294

295-
private void processMakeBlocks(Dictionary<int, byte[]> blockDataDict, string upToken,
296-
PutExtra putExtra, ResumeInfo resumeInfo, Dictionary<int, HttpResult> blockMakeResults,
297-
Dictionary<string,long> uploadedBytesDict, long fileSize)
295+
private void processMakeBlocks(Dictionary<long, byte[]> blockDataDict, string upToken,
296+
PutExtra putExtra, ResumeInfo resumeInfo, Dictionary<long, HttpResult> blockMakeResults,
297+
Dictionary<string, long> uploadedBytesDict, long fileSize)
298298
{
299299
int taskMax = blockDataDict.Count;
300300
ManualResetEvent[] doneEvents = new ManualResetEvent[taskMax];
301301
int eventIndex = 0;
302302
object progressLock = new object();
303-
foreach (int blockIndex in blockDataDict.Keys)
303+
foreach (long blockIndex in blockDataDict.Keys)
304304
{
305305
//signal task
306306
ManualResetEvent doneEvent = new ManualResetEvent(false);
@@ -333,9 +333,9 @@ private void MakeBlock(object resumeBlockerObj)
333333
{
334334
ResumeBlocker resumeBlocker = (ResumeBlocker)resumeBlockerObj;
335335
ManualResetEvent doneEvent = resumeBlocker.DoneEvent;
336-
Dictionary<int, HttpResult> blockMakeResults = resumeBlocker.BlockMakeResults;
336+
Dictionary<long, HttpResult> blockMakeResults = resumeBlocker.BlockMakeResults;
337337
PutExtra putExtra = resumeBlocker.PutExtra;
338-
int blockIndex = resumeBlocker.BlockIndex;
338+
long blockIndex = resumeBlocker.BlockIndex;
339339
HttpResult result = new HttpResult();
340340
//check whether to cancel
341341
while (true)
@@ -353,8 +353,8 @@ private void MakeBlock(object resumeBlockerObj)
353353
result.Code = (int)HttpCode.USER_CANCELED;
354354
result.RefCode = (int)HttpCode.USER_CANCELED;
355355
result.RefText += string.Format("[{0}] [ResumableUpload] Info: upload task is aborted, mkblk {1}\n",
356-
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"),blockIndex);
357-
blockMakeResults.Add(blockIndex,result);
356+
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"), blockIndex);
357+
blockMakeResults.Add(blockIndex, result);
358358
return;
359359
}
360360
else
@@ -365,7 +365,7 @@ private void MakeBlock(object resumeBlockerObj)
365365

366366
byte[] blockBuffer = resumeBlocker.BlockBuffer;
367367
int blockSize = blockBuffer.Length;
368-
368+
369369
string upToken = resumeBlocker.UploadToken;
370370
Dictionary<string, long> uploadedBytesDict = resumeBlocker.UploadedBytesDict;
371371
long fileSize = resumeBlocker.FileSize;

src/Qiniu/Storage/ResumeBlocker.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ class ResumeBlocker
88
{
99
public ManualResetEvent DoneEvent { set; get; }
1010
public byte[] BlockBuffer { set; get; }
11-
public int BlockIndex { set; get; }
11+
public long BlockIndex { set; get; }
1212
public string UploadToken { set; get; }
1313
public PutExtra PutExtra { set; get; }
1414
public ResumeInfo ResumeInfo { set; get; }
15-
public Dictionary<int, HttpResult> BlockMakeResults;
15+
public Dictionary<long, HttpResult> BlockMakeResults;
1616
public object ProgressLock { set; get; }
1717
public Dictionary<string, long> UploadedBytesDict { set; get; }
1818
public long FileSize { set; get; }
1919

20-
public ResumeBlocker(ManualResetEvent doneEvent, byte[] blockBuffer, int blockIndex, string uploadToken,
21-
PutExtra putExtra, ResumeInfo resumeInfo, Dictionary<int, HttpResult> blockMakeResults,
20+
public ResumeBlocker(ManualResetEvent doneEvent, byte[] blockBuffer, long blockIndex, string uploadToken,
21+
PutExtra putExtra, ResumeInfo resumeInfo, Dictionary<long, HttpResult> blockMakeResults,
2222
object progressLock, Dictionary<string, long> uploadedBytesDict, long fileSize)
2323
{
2424
this.DoneEvent = doneEvent;

src/Qiniu/Storage/ResumeInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ResumeInfo
1616
/// 文件块总数
1717
/// </summary>
1818
[JsonProperty("blockCount")]
19-
public int BlockCount { get; set; }
19+
public long BlockCount { get; set; }
2020

2121
/// <summary>
2222
/// 上下文信息列表

src/Qiniu/Util/Signature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Signature(Mac mac)
3131
private string encodedSign(byte[] data)
3232
{
3333
HMACSHA1 hmac = new HMACSHA1(Encoding.UTF8.GetBytes(mac.SecretKey));
34-
byte[] digest = hmac.ComputeHash(data);
34+
byte[] digest = hmac.ComputeHash(data);
3535
return Base64.UrlSafeBase64Encode(digest);
3636
}
3737

@@ -48,7 +48,7 @@ private string encodedSign(string str)
4848
/// <returns></returns>
4949
public string Sign(byte[] data)
5050
{
51-
return string.Format("{0}:{1}", mac.AccessKey,encodedSign(data));
51+
return string.Format("{0}:{1}", mac.AccessKey, encodedSign(data));
5252
}
5353

5454
/// <summary>

0 commit comments

Comments
 (0)