use AZURE_ASSERT in storage code (#2262)

* use AZURE_ASSERT in storage code

* fix build

* clang-format

* fix
This commit is contained in:
JinmingHu 2021-05-17 10:06:26 +08:00 committed by GitHub
parent 92839dcc56
commit af936e052f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 110 additions and 116 deletions

View File

@ -52,5 +52,5 @@
[[noreturn]] void AzureNoReturnPath(std::string const& msg);
#define AZURE_ASSERT_FALSE(exp) AZURE_ASSERT(!(exp))
#define AZURE_UNREACHABLE_CODE AzureNoReturnPath("unreachable code!")
#define AZURE_NOT_IMPLEMENTED AzureNoReturnPath("not implemented code!")
#define AZURE_UNREACHABLE_CODE() AzureNoReturnPath("unreachable code!")
#define AZURE_NOT_IMPLEMENTED() AzureNoReturnPath("not implemented code!")

View File

@ -114,7 +114,7 @@ public:
break;
}
// Unknown comparison
AZURE_UNREACHABLE_CODE;
AZURE_UNREACHABLE_CODE();
}
/**

View File

@ -187,11 +187,7 @@ namespace Azure { namespace Storage {
~StartBlobCopyOperation() override {}
private:
std::string GetResumeToken() const override
{
// Not supported
std::abort();
}
std::string GetResumeToken() const override { AZURE_NOT_IMPLEMENTED(); }
std::unique_ptr<Azure::Core::Http::RawResponse> PollInternal(
const Azure::Core::Context& context) override;

View File

@ -3,6 +3,7 @@
#include "azure/storage/blobs/blob_lease_client.hpp"
#include <azure/core/azure_assert.hpp>
#include <azure/core/uuid.hpp>
namespace Azure { namespace Storage { namespace Blobs {
@ -52,12 +53,16 @@ namespace Azure { namespace Storage { namespace Blobs {
protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince;
if (options.AccessConditions.IfMatch.HasValue()
|| options.AccessConditions.IfNoneMatch.HasValue()
|| options.AccessConditions.TagConditions.HasValue())
{
std::abort();
}
AZURE_ASSERT_MSG(
!options.AccessConditions.IfMatch.HasValue(),
"Blob container lease doesn't support If-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.IfNoneMatch.HasValue(),
"Blob container lease doesn't support If-None-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.TagConditions.HasValue(),
"Blob container lease doesn't support tag condition");
auto response = _detail::BlobRestClient::BlobContainer::AcquireLease(
*(m_blobContainerClient.Value().m_pipeline),
m_blobContainerClient.Value().m_blobContainerUrl,
@ -74,7 +79,7 @@ namespace Azure { namespace Storage { namespace Blobs {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -113,12 +118,15 @@ namespace Azure { namespace Storage { namespace Blobs {
protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince;
if (options.AccessConditions.IfMatch.HasValue()
|| options.AccessConditions.IfNoneMatch.HasValue()
|| options.AccessConditions.TagConditions.HasValue())
{
std::abort();
}
AZURE_ASSERT_MSG(
!options.AccessConditions.IfMatch.HasValue(),
"Blob container lease doesn't support If-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.IfNoneMatch.HasValue(),
"Blob container lease doesn't support If-None-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.TagConditions.HasValue(),
"Blob container lease doesn't support tag condition");
auto response = _detail::BlobRestClient::BlobContainer::RenewLease(
*(m_blobContainerClient.Value().m_pipeline),
@ -136,7 +144,7 @@ namespace Azure { namespace Storage { namespace Blobs {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -174,12 +182,15 @@ namespace Azure { namespace Storage { namespace Blobs {
protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince;
if (options.AccessConditions.IfMatch.HasValue()
|| options.AccessConditions.IfNoneMatch.HasValue()
|| options.AccessConditions.TagConditions.HasValue())
{
std::abort();
}
AZURE_ASSERT_MSG(
!options.AccessConditions.IfMatch.HasValue(),
"Blob container lease doesn't support If-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.IfNoneMatch.HasValue(),
"Blob container lease doesn't support If-None-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.TagConditions.HasValue(),
"Blob container lease doesn't support tag condition");
auto response = _detail::BlobRestClient::BlobContainer::ReleaseLease(
*(m_blobContainerClient.Value().m_pipeline),
@ -196,7 +207,7 @@ namespace Azure { namespace Storage { namespace Blobs {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -243,12 +254,15 @@ namespace Azure { namespace Storage { namespace Blobs {
protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince;
if (options.AccessConditions.IfMatch.HasValue()
|| options.AccessConditions.IfNoneMatch.HasValue()
|| options.AccessConditions.TagConditions.HasValue())
{
std::abort();
}
AZURE_ASSERT_MSG(
!options.AccessConditions.IfMatch.HasValue(),
"Blob container lease doesn't support If-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.IfNoneMatch.HasValue(),
"Blob container lease doesn't support If-None-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.TagConditions.HasValue(),
"Blob container lease doesn't support tag condition");
auto response = _detail::BlobRestClient::BlobContainer::ChangeLease(
*(m_blobContainerClient.Value().m_pipeline),
@ -271,7 +285,7 @@ namespace Azure { namespace Storage { namespace Blobs {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -309,12 +323,15 @@ namespace Azure { namespace Storage { namespace Blobs {
protocolLayerOptions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
protocolLayerOptions.IfUnmodifiedSince = options.AccessConditions.IfUnmodifiedSince;
if (options.AccessConditions.IfMatch.HasValue()
|| options.AccessConditions.IfNoneMatch.HasValue()
|| options.AccessConditions.TagConditions.HasValue())
{
std::abort();
}
AZURE_ASSERT_MSG(
!options.AccessConditions.IfMatch.HasValue(),
"Blob container lease doesn't support If-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.IfNoneMatch.HasValue(),
"Blob container lease doesn't support If-None-Match condition");
AZURE_ASSERT_MSG(
!options.AccessConditions.TagConditions.HasValue(),
"Blob container lease doesn't support tag condition");
auto response = _detail::BlobRestClient::BlobContainer::BreakLease(
*(m_blobContainerClient.Value().m_pipeline),
@ -331,7 +348,7 @@ namespace Azure { namespace Storage { namespace Blobs {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
}}} // namespace Azure::Storage::Blobs

View File

@ -103,8 +103,7 @@ namespace Azure { namespace Storage { namespace Blobs {
*this = m_pageBlobClient->GetManagedDiskPageRangesDiff(
m_previousSnapshotUrl.Value(), m_operationOptions, context);
}
// Execution is never expected to reach here
std::abort();
AZURE_UNREACHABLE_CODE();
}
}}} // namespace Azure::Storage::Blobs

View File

@ -63,11 +63,6 @@ namespace Azure { namespace Storage { namespace _internal {
{
handle.get();
}
if (numWorkingThreads != 0)
{
std::abort();
}
}
}}} // namespace Azure::Storage::_internal

View File

@ -157,10 +157,11 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
protocolLayerOptions.RetainUncommittedData = options.RetainUncommittedData;
protocolLayerOptions.Close = options.Close;
protocolLayerOptions.ContentLength = 0;
if (options.ContentHash.HasValue()
&& options.ContentHash.Value().Algorithm != HashAlgorithm::Md5)
if (options.ContentHash.HasValue())
{
std::abort();
AZURE_ASSERT_MSG(
options.ContentHash.Value().Algorithm == HashAlgorithm::Md5,
"This operation only supports MD5 content hash.");
}
protocolLayerOptions.ContentMd5 = options.ContentHash;
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
@ -376,11 +377,10 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
Blobs::_detail::BlobRestClient::Blob::SetBlobExpiryOptions protocolLayerOptions;
protocolLayerOptions.ExpiryOrigin = expiryOrigin;
if (options.ExpiresOn.HasValue() && options.TimeToExpire.HasValue())
{
// ExpiresOn and TimeToExpire should be mutually exclusive.
std::abort();
}
AZURE_ASSERT_MSG(
!(options.ExpiresOn.HasValue() && options.TimeToExpire.HasValue()),
"ExpiresOn and TimeToExpire are mutually exclusive");
if (options.ExpiresOn.HasValue())
{
protocolLayerOptions.ExpiryTime

View File

@ -251,10 +251,10 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
Blobs::SetBlobContainerMetadataOptions blobOptions;
blobOptions.AccessConditions.IfModifiedSince = options.AccessConditions.IfModifiedSince;
if (options.AccessConditions.IfUnmodifiedSince.HasValue())
{
std::abort();
}
AZURE_ASSERT_MSG(
!options.AccessConditions.IfUnmodifiedSince.HasValue(),
"This operation doesn't support If-Unmodified-Since condition");
auto result = m_blobContainerClient.SetMetadata(std::move(metadata), blobOptions, context);
Models::SetFileSystemMetadataResult ret;
ret.ETag = std::move(result.Value.ETag);

View File

@ -111,8 +111,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*this = m_dataLakePathClient->RemoveAccessControlListRecursive(
m_acls, m_operationOptions, context);
}
// Execution is never expected to reach here
std::abort();
AZURE_UNREACHABLE_CODE();
}
}}}} // namespace Azure::Storage::Files::DataLake

View File

@ -226,11 +226,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
~StartFileCopyOperation() override {}
private:
std::string GetResumeToken() const override
{
// Not supported
std::abort();
}
std::string GetResumeToken() const override { AZURE_NOT_IMPLEMENTED(); }
std::unique_ptr<Azure::Core::Http::RawResponse> PollInternal(
const Azure::Core::Context& context) override;

View File

@ -166,10 +166,9 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
if (!options.HttpHeaders.ContentHash.Value.empty())
{
if (options.HttpHeaders.ContentHash.Algorithm != HashAlgorithm::Md5)
{
std::abort();
}
AZURE_ASSERT_MSG(
options.HttpHeaders.ContentHash.Algorithm == HashAlgorithm::Md5,
"This operation only supports MD5 content hash");
protocolLayerOptions.ContentMd5 = options.HttpHeaders.ContentHash;
}
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
@ -241,14 +240,13 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
if (options.RangeHashAlgorithm.HasValue())
{
AZURE_ASSERT_MSG(
options.RangeHashAlgorithm.Value() == HashAlgorithm::Md5,
"This operation only supports MD5 content hash");
if (options.RangeHashAlgorithm.Value() == HashAlgorithm::Md5)
{
protocolLayerOptions.GetRangeContentMd5 = true;
}
else
{
std::abort();
}
}
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
@ -353,9 +351,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
// FilePermission or FilePermissionKey must be set if FilePermissionCopyMode is set to
// PermissionCopyModeType::Override.
std::abort();
AZURE_ASSERT_MSG(false, "Either FilePermission or FilePermissionKey must be set");
}
}
}
@ -490,10 +486,11 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.ContentLength = content.Length();
protocolLayerOptions.XMsRange = std::string("bytes=") + std::to_string(offset)
+ std::string("-") + std::to_string(offset + content.Length() - 1);
if (options.TransactionalContentHash.HasValue()
&& options.TransactionalContentHash.Value().Algorithm != HashAlgorithm::Md5)
if (options.TransactionalContentHash.HasValue())
{
std::abort();
AZURE_ASSERT_MSG(
options.TransactionalContentHash.Value().Algorithm == HashAlgorithm::Md5,
"This operation only supports MD5 content hash");
}
protocolLayerOptions.ContentMd5 = options.TransactionalContentHash;
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
@ -930,10 +927,9 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
if (!options.HttpHeaders.ContentHash.Value.empty())
{
if (options.HttpHeaders.ContentHash.Algorithm != HashAlgorithm::Md5)
{
std::abort();
}
AZURE_ASSERT_MSG(
options.HttpHeaders.ContentHash.Algorithm == HashAlgorithm::Md5,
"This operation only supports MD5 content hash");
protocolLayerOptions.ContentMd5 = options.HttpHeaders.ContentHash;
}
protocolLayerOptions.Metadata = options.Metadata;
@ -1033,10 +1029,9 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
if (!options.HttpHeaders.ContentHash.Value.empty())
{
if (options.HttpHeaders.ContentHash.Algorithm != HashAlgorithm::Md5)
{
std::abort();
}
AZURE_ASSERT_MSG(
options.HttpHeaders.ContentHash.Algorithm == HashAlgorithm::Md5,
"This operation only supports MD5 content hash");
protocolLayerOptions.ContentMd5 = options.HttpHeaders.ContentHash;
}
protocolLayerOptions.Metadata = options.Metadata;
@ -1078,11 +1073,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
const UploadFileRangeFromUriOptions& options,
const Azure::Core::Context& context) const
{
if (!sourceRange.Length.HasValue())
{
// sourceRange must have length to perform this operation.
std::abort();
}
AZURE_ASSERT_MSG(sourceRange.Length.HasValue(), "Source length cannot be null");
int64_t rangeLength = sourceRange.Length.Value();
auto protocolLayerOptions = _detail::ShareRestClient::File::UploadRangeFromUrlOptions();
@ -1091,26 +1082,27 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.ContentLength = 0;
protocolLayerOptions.CopySource = sourceUri;
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
if (options.TransactionalContentHash.HasValue()
&& options.TransactionalContentHash.Value().Algorithm == HashAlgorithm::Md5)
if (options.TransactionalContentHash.HasValue())
{
// SourceContentHash now only supports Crc64 hash algorithm.
std::abort();
AZURE_ASSERT_MSG(
options.TransactionalContentHash.Value().Algorithm == HashAlgorithm::Crc64,
"This operation only supports CRC64 content hash");
}
protocolLayerOptions.SourceContentCrc64 = options.TransactionalContentHash;
if (options.SourceAccessCondition.IfMatchContentHash.HasValue()
&& options.SourceAccessCondition.IfMatchContentHash.Value().Algorithm == HashAlgorithm::Md5)
if (options.SourceAccessCondition.IfMatchContentHash.HasValue())
{
// IfMatchContentHash now only supports Crc64 hash algorithm.
std::abort();
AZURE_ASSERT_MSG(
options.SourceAccessCondition.IfMatchContentHash.Value().Algorithm
== HashAlgorithm::Crc64,
"This operation only supports CRC64 Source-If-Match condition");
}
protocolLayerOptions.SourceIfMatchCrc64 = options.SourceAccessCondition.IfMatchContentHash;
if (options.SourceAccessCondition.IfNoneMatchContentHash.HasValue()
&& options.SourceAccessCondition.IfNoneMatchContentHash.Value().Algorithm
== HashAlgorithm::Md5)
if (options.SourceAccessCondition.IfNoneMatchContentHash.HasValue())
{
// IfNoneMatchContentHash now only supports Crc64 hash algorithm.
std::abort();
AZURE_ASSERT_MSG(
options.SourceAccessCondition.IfNoneMatchContentHash.Value().Algorithm
== HashAlgorithm::Crc64,
"This operation only supports CRC64 Source-If-None-Match condition");
}
protocolLayerOptions.SourceIfNoneMatchCrc64
= options.SourceAccessCondition.IfNoneMatchContentHash;

View File

@ -62,7 +62,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -73,8 +73,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
(void)options;
if (m_fileClient.HasValue())
{
// Renew only support share level lease.
std::abort();
AZURE_ASSERT_MSG(false, "Share lease doesn't support renew");
AZURE_NOT_IMPLEMENTED();
}
else if (m_shareClient.HasValue())
{
@ -97,7 +97,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -144,7 +144,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -206,7 +206,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
@ -251,7 +251,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
std::abort();
AZURE_UNREACHABLE_CODE();
}
}
}}}} // namespace Azure::Storage::Files::Shares