Skip to content

Commit

Permalink
[Storage] Ctor allocations (#21424)
Browse files Browse the repository at this point in the history
* this gets allocations in line. but isn't great.

* temporarily disable the probe.

* try Azure/autorest#4152

* Revert "temporarily disable the probe."

This reverts commit f5d1587.

* fix empty path.

* mocking.

* fix 403.

* I really dislike url-encoding...

* private protected. nice.

* fix tests.

* datalake.

* fix that.

* shares.

* queues

* batch.

* this works.

* this works. too.
  • Loading branch information
kasobol-msft authored Jun 5, 2021
1 parent 2751573 commit 9472dbf
Show file tree
Hide file tree
Showing 54 changed files with 1,009 additions and 1,816 deletions.
14 changes: 5 additions & 9 deletions sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public BlobBatchClient(BlobServiceClient client)
BlobServiceClientInternals.GetAuthenticationPolicy(client),
_version);

(ServiceRestClient serviceRestClient, ContainerRestClient containerRestClient) = BuildRestClients();
(ServiceRestClient serviceRestClient, ContainerRestClient containerRestClient) = BuildRestClients(_uri);
_serviceRestClient = serviceRestClient;
_containerRestClient = containerRestClient;

Expand Down Expand Up @@ -180,7 +180,7 @@ public BlobBatchClient(BlobContainerClient client)
BlobServiceClientInternals.GetAuthenticationPolicy(blobServiceClient),
_version);

(ServiceRestClient serviceRestClient, ContainerRestClient containerRestClient) = BuildRestClients();
(ServiceRestClient serviceRestClient, ContainerRestClient containerRestClient) = BuildRestClients(blobServiceClient.Uri);
_serviceRestClient = serviceRestClient;
_containerRestClient = containerRestClient;
_containerName = client.Name;
Expand Down Expand Up @@ -224,22 +224,18 @@ private static HttpPipeline CreateBatchPipeline(
authenticationPolicy);
}

private (ServiceRestClient ServiceClient, ContainerRestClient ContainerClient) BuildRestClients()
private (ServiceRestClient ServiceClient, ContainerRestClient ContainerClient) BuildRestClients(Uri serviceUri)
{
BlobUriBuilder uriBuilder = new BlobUriBuilder(_uri);
uriBuilder.BlobContainerName = null;
uriBuilder.BlobName = null;

ServiceRestClient serviceRestClient = new ServiceRestClient(
clientDiagnostics: _clientDiagnostics,
pipeline: _pipeline,
url: uriBuilder.ToUri().ToString(),
url: serviceUri.AbsoluteUri,
version: _version.ToVersionString());

ContainerRestClient containerRestClient = new ContainerRestClient(
clientDiagnostics: _clientDiagnostics,
pipeline: _pipeline,
url: uriBuilder.ToUri().ToString(),
url: serviceUri.AbsoluteUri,
version: _version.ToVersionString());

return (serviceRestClient, containerRestClient);
Expand Down
37 changes: 4 additions & 33 deletions sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ protected AppendBlobClient()
public AppendBlobClient(string connectionString, string blobContainerName, string blobName)
: base(connectionString, blobContainerName, blobName)
{
_appendBlobRestClient = BuildAppendBlobRestClient(
connectionString,
blobContainerName,
blobName);
_appendBlobRestClient = BuildAppendBlobRestClient(_uri);
}

/// <summary>
Expand Down Expand Up @@ -115,10 +112,7 @@ public AppendBlobClient(string connectionString, string blobContainerName, strin
public AppendBlobClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options)
: base(connectionString, blobContainerName, blobName, options)
{
_appendBlobRestClient = BuildAppendBlobRestClient(
connectionString,
blobContainerName,
blobName);
_appendBlobRestClient = BuildAppendBlobRestClient(_uri);
AssertNoClientSideEncryption(options);
}

Expand Down Expand Up @@ -255,35 +249,12 @@ private static void AssertNoClientSideEncryption(BlobClientOptions options)
}
}

private AppendBlobRestClient BuildAppendBlobRestClient(Uri uri)
=> BuildAppendBlobRestClient(new BlobUriBuilder(uri));

private AppendBlobRestClient BuildAppendBlobRestClient(
string connectionString,
string blobContainerName,
string blobName)
{
StorageConnectionString conn = StorageConnectionString.Parse(connectionString);
BlobUriBuilder uriBuilder = new BlobUriBuilder(conn.BlobEndpoint)
{
BlobContainerName = blobContainerName,
BlobName = blobName
};
return BuildAppendBlobRestClient(uriBuilder);
}

private AppendBlobRestClient BuildAppendBlobRestClient(BlobUriBuilder uriBuilder)
private AppendBlobRestClient BuildAppendBlobRestClient(Uri blobUri)
{
string containerName = uriBuilder.BlobContainerName;
string blobName = uriBuilder.BlobName;
uriBuilder.BlobContainerName = null;
uriBuilder.BlobName = null;
return new AppendBlobRestClient(
clientDiagnostics: _clientConfiguration.ClientDiagnostics,
pipeline: _clientConfiguration.Pipeline,
url: uriBuilder.ToUri().ToString(),
containerName: containerName,
blob: blobName.EscapePath(),
url: blobUri.AbsoluteUri,
version: _clientConfiguration.Version.ToVersionString());
}
#endregion ctors
Expand Down
38 changes: 4 additions & 34 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class BlobBaseClient
/// <summary>
/// The blob's primary <see cref="Uri"/> endpoint.
/// </summary>
private readonly Uri _uri;
private protected readonly Uri _uri;

/// <summary>
/// Gets the blob's primary <see cref="Uri"/> endpoint.
Expand Down Expand Up @@ -166,10 +166,6 @@ protected BlobBaseClient()
public BlobBaseClient(string connectionString, string blobContainerName, string blobName)
: this(connectionString, blobContainerName, blobName, null)
{
_blobRestClient = BuildBlobRestClient(
connectionString,
blobContainerName,
blobName);
}

/// <summary>
Expand Down Expand Up @@ -217,10 +213,7 @@ public BlobBaseClient(string connectionString, string blobContainerName, string
encryptionScope: options.EncryptionScope);

_clientSideEncryption = options._clientSideEncryptionOptions?.Clone();
_blobRestClient = BuildBlobRestClient(
connectionString,
blobContainerName,
blobName);
_blobRestClient = BuildBlobRestClient(_uri);

BlobErrors.VerifyHttpsCustomerProvidedKey(_uri, _clientConfiguration.CustomerProvidedKey);
BlobErrors.VerifyCpkAndEncryptionScopeNotBothSet(_clientConfiguration.CustomerProvidedKey, _clientConfiguration.EncryptionScope);
Expand Down Expand Up @@ -425,35 +418,12 @@ internal BlobBaseClient(
BlobErrors.VerifyCpkAndEncryptionScopeNotBothSet(_clientConfiguration.CustomerProvidedKey, _clientConfiguration.EncryptionScope);
}

private BlobRestClient BuildBlobRestClient(Uri uri)
=> BuildBlobRestClient(new BlobUriBuilder(uri));

private BlobRestClient BuildBlobRestClient(
string connectionString,
string blobContainerName,
string blobName)
{
StorageConnectionString conn = StorageConnectionString.Parse(connectionString);
BlobUriBuilder uriBuilder = new BlobUriBuilder(conn.BlobEndpoint)
{
BlobContainerName = blobContainerName,
BlobName = blobName,
};
return BuildBlobRestClient(uriBuilder);
}

private BlobRestClient BuildBlobRestClient(BlobUriBuilder uriBuilder)
private BlobRestClient BuildBlobRestClient(Uri blobUri)
{
string containerName = uriBuilder.BlobContainerName;
string blobName = uriBuilder.BlobName;
uriBuilder.BlobContainerName = null;
uriBuilder.BlobName = null;
return new BlobRestClient(
clientDiagnostics: _clientConfiguration.ClientDiagnostics,
pipeline: _clientConfiguration.Pipeline,
url: uriBuilder.ToUri().ToString(),
containerName: containerName,
blob: blobName.EscapePath(),
url: blobUri.AbsoluteUri,
version: _clientConfiguration.Version.ToVersionString());
}
#endregion ctors
Expand Down
9 changes: 2 additions & 7 deletions sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,12 @@ protected static BlobContainerClient CreateClient(Uri containerUri, BlobClientOp
clientSideEncryption: null);
}

private ContainerRestClient BuildContainerRestClient(Uri uri)
private ContainerRestClient BuildContainerRestClient(Uri containerUri)
{
BlobUriBuilder uriBuilder = new BlobUriBuilder(uri);
string containerName = uriBuilder.BlobContainerName;
uriBuilder.BlobContainerName = null;

return new ContainerRestClient(
clientDiagnostics: _clientConfiguration.ClientDiagnostics,
pipeline: _clientConfiguration.Pipeline,
url: uriBuilder.ToString(),
containerName: containerName,
url: containerUri.AbsoluteUri,
version: _clientConfiguration.Version.ToVersionString());
}
#endregion ctor
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobUriBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private RequestUriBuilder BuildUri()
path.Append('/').Append(BlobContainerName);
if (BlobName != null && BlobName.Length > 0)
{
path.Append('/').Append(Uri.EscapeDataString(BlobName));
path.Append('/').Append(BlobName.EscapePath());
}
}

Expand Down
37 changes: 4 additions & 33 deletions sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ protected BlockBlobClient()
public BlockBlobClient(string connectionString, string containerName, string blobName)
: base(connectionString, containerName, blobName)
{
_blockBlobRestClient = BuildBlockBlobRestClient(
connectionString,
containerName,
blobName);
_blockBlobRestClient = BuildBlockBlobRestClient(_uri);
}

/// <summary>
Expand Down Expand Up @@ -204,10 +201,7 @@ public BlockBlobClient(string connectionString, string containerName, string blo
public BlockBlobClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options)
: base(connectionString, blobContainerName, blobName, options)
{
_blockBlobRestClient = BuildBlockBlobRestClient(
connectionString,
blobContainerName,
blobName);
_blockBlobRestClient = BuildBlockBlobRestClient(_uri);
AssertNoClientSideEncryption(options);
}

Expand Down Expand Up @@ -372,35 +366,12 @@ private static void AssertNoClientSideEncryption(BlobClientOptions options)
}
}

private BlockBlobRestClient BuildBlockBlobRestClient(
string connectionString,
string blobContainerName,
string blobName)
{
StorageConnectionString conn = StorageConnectionString.Parse(connectionString);
BlobUriBuilder uriBuilder = new BlobUriBuilder(conn.BlobEndpoint)
{
BlobContainerName = blobContainerName,
BlobName = blobName
};
return BuildBlockBlobRestClient(uriBuilder);
}

private BlockBlobRestClient BuildBlockBlobRestClient(Uri uri)
=> BuildBlockBlobRestClient(new BlobUriBuilder(uri));

private BlockBlobRestClient BuildBlockBlobRestClient(BlobUriBuilder uriBuilder)
private BlockBlobRestClient BuildBlockBlobRestClient(Uri blobUri)
{
string containerName = uriBuilder.BlobContainerName;
string blobName = uriBuilder.BlobName;
uriBuilder.BlobContainerName = null;
uriBuilder.BlobName = null;
return new BlockBlobRestClient(
clientDiagnostics: _clientConfiguration.ClientDiagnostics,
pipeline: _clientConfiguration.Pipeline,
url: uriBuilder.ToUri().ToString(),
containerName: containerName,
blob: blobName.EscapePath(),
url: blobUri.AbsoluteUri,
version: _clientConfiguration.Version.ToVersionString());
}
#endregion ctors
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading

0 comments on commit 9472dbf

Please sign in to comment.