fix read consistency issue (#2364)

This commit is contained in:
JinmingHu 2021-05-30 10:36:49 +08:00 committed by GitHub
parent 15c525d387
commit 38bd273d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 14 deletions

View File

@ -191,10 +191,7 @@ namespace Azure { namespace Storage { namespace Blobs {
{
newOptions.Range.Value().Length = options.Range.Value().Length.Value() - retryOffset;
}
if (!newOptions.AccessConditions.IfMatch.HasValue())
{
newOptions.AccessConditions.IfMatch = eTag;
}
newOptions.AccessConditions.IfMatch = eTag;
return std::move(Download(newOptions, context).Value.BodyStream);
};
@ -291,10 +288,7 @@ namespace Azure { namespace Storage { namespace Blobs {
chunkOptions.Range = Core::Http::HttpRange();
chunkOptions.Range.Value().Offset = offset;
chunkOptions.Range.Value().Length = length;
if (!chunkOptions.AccessConditions.IfMatch.HasValue())
{
chunkOptions.AccessConditions.IfMatch = eTag;
}
chunkOptions.AccessConditions.IfMatch = eTag;
auto chunk = Download(chunkOptions, context);
int64_t bytesRead = chunk.Value.BodyStream->ReadToCount(
buffer + (offset - firstChunkOffset),
@ -417,10 +411,7 @@ namespace Azure { namespace Storage { namespace Blobs {
chunkOptions.Range = Core::Http::HttpRange();
chunkOptions.Range.Value().Offset = offset;
chunkOptions.Range.Value().Length = length;
if (!chunkOptions.AccessConditions.IfMatch.HasValue())
{
chunkOptions.AccessConditions.IfMatch = eTag;
}
chunkOptions.AccessConditions.IfMatch = eTag;
auto chunk = Download(chunkOptions, context);
bodyStreamToFile(
*(chunk.Value.BodyStream),

View File

@ -272,8 +272,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
auto newResponse = Download(newOptions, context);
if (eTag != newResponse.Value.Details.ETag)
{
throw Azure::Core::RequestFailedException(
"File was changed during the download process.");
throw Azure::Core::RequestFailedException("file was modified in the middle of download");
}
return std::move(newResponse.Value.BodyStream);
};
@ -669,6 +668,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
auto firstChunk = Download(firstChunkOptions, context);
const Azure::ETag etag = firstChunk.Value.Details.ETag;
int64_t fileSize;
int64_t fileRangeSize;
@ -728,6 +728,11 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
{
throw Azure::Core::RequestFailedException("error when reading body stream");
}
if (chunk.Value.Details.ETag != etag)
{
throw Azure::Core::RequestFailedException(
"file was modified in the middle of download");
}
if (chunkId == numChunks - 1)
{
@ -774,6 +779,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
_internal::FileWriter fileWriter(fileName);
auto firstChunk = Download(firstChunkOptions, context);
const Azure::ETag etag = firstChunk.Value.Details.ETag;
int64_t fileSize;
int64_t fileRangeSize;
@ -840,6 +846,11 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
chunkOptions.Range.Value().Offset = offset;
chunkOptions.Range.Value().Length = length;
auto chunk = Download(chunkOptions, context);
if (chunk.Value.Details.ETag != etag)
{
throw Azure::Core::RequestFailedException(
"file was modified in the middle of download");
}
bodyStreamToFile(
*(chunk.Value.BodyStream),
fileWriter,