Skip to content

Commit 5a08b79

Browse files
authored
Fix Db2Catalog and Catalog2Dnx with new SDK changes (#10110)
* Sanitize URLs for logging * Fix container URI construction when directory is provided * Remove flaky assertion
1 parent b16859d commit 5a08b79

8 files changed

Lines changed: 62 additions & 551 deletions

File tree

src/Catalog/Persistence/AzureStorage.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public AzureStorage(
129129

130130
if (initializeContainer)
131131
{
132-
BlobContainerInfo blobContainerInfo = _blobContainerClientWrapper.ContainerClient.CreateIfNotExists(PublicAccessType.Blob);
132+
Response<BlobContainerInfo> blobContainerInfoResponse = _blobContainerClientWrapper.ContainerClient.CreateIfNotExists(PublicAccessType.Blob);
133133

134-
if (blobContainerInfo != null && Verbose)
134+
if (blobContainerInfoResponse?.Value != null && Verbose)
135135
{
136136
Trace.WriteLine($"Created '{_blobContainerClientWrapper.ContainerClient.Name}' public container");
137137
}
@@ -192,10 +192,10 @@ public override async Task<IEnumerable<StorageListItem>> ListAsync(CancellationT
192192
var blobs = new List<StorageListItem>();
193193

194194
BlobContainerClient blobContainerClient = _blobContainerClientWrapper.ContainerClient;
195-
await foreach (var blobItem in blobContainerClient.GetBlobsAsync(prefix: _directory.DirectoryPrefix, cancellationToken: cancellationToken))
195+
await foreach (var blobItem in blobContainerClient.GetBlobsByHierarchyAsync(prefix: _directory.DirectoryPrefix, cancellationToken: cancellationToken))
196196
{
197-
var lastModified = blobItem.Properties.LastModified?.UtcDateTime;
198-
blobs.Add(new StorageListItem(new Uri(blobContainerClient.Uri, blobItem.Name), lastModified));
197+
var lastModified = blobItem.Blob.Properties.LastModified?.UtcDateTime;
198+
blobs.Add(new StorageListItem(blobContainerClient.GetBlobClient(blobItem.Blob.Name).Uri, lastModified));
199199
}
200200

201201
return blobs;
@@ -314,7 +314,7 @@ protected override async Task OnSaveAsync(Uri resourceUri, StorageContent conten
314314

315315
await blockBlobClient.UploadAsync(destinationStream, headers, conditions: blobRequestConditions, cancellationToken: cancellationToken);
316316

317-
Trace.WriteLine($"Saved compressed blob {blockBlobClient.Uri} to container {_blobContainerClientWrapper.ContainerClient.Name}");
317+
Trace.WriteLine($"Saved compressed blob {RemoveQueryString(blockBlobClient.Uri)} to container {_blobContainerClientWrapper.ContainerClient.Name}");
318318
}
319319
}
320320
else
@@ -323,7 +323,7 @@ protected override async Task OnSaveAsync(Uri resourceUri, StorageContent conten
323323
{
324324
await blockBlobClient.UploadAsync(stream, headers, cancellationToken: cancellationToken);
325325

326-
Trace.WriteLine($"Saved uncompressed blob {blockBlobClient.Uri} to container {_blobContainerClientWrapper.ContainerClient.Name}");
326+
Trace.WriteLine($"Saved uncompressed blob {RemoveQueryString(blockBlobClient.Uri)} to container {_blobContainerClientWrapper.ContainerClient.Name}");
327327
}
328328
}
329329

@@ -351,14 +351,14 @@ private async Task<bool> TryTakeBlobSnapshotAsync(BlockBlobClient blobBlockClien
351351
{
352352
var response = await blobBlockClient.CreateSnapshotAsync();
353353
stopwatch.Stop();
354-
Trace.WriteLine($"SnapshotCreated:milliseconds={stopwatch.ElapsedMilliseconds}:{blobBlockClient.Uri.ToString()}:{response?.Value.Snapshot}");
354+
Trace.WriteLine($"SnapshotCreated:milliseconds={stopwatch.ElapsedMilliseconds}:{RemoveQueryString(blobBlockClient.Uri)}:{response?.Value.Snapshot}");
355355
}
356356
return true;
357357
}
358358
catch (RequestFailedException e)
359359
{
360360
stopwatch.Stop();
361-
Trace.WriteLine($"EXCEPTION:milliseconds={stopwatch.ElapsedMilliseconds}:CreateSnapshot: Failed to take the snapshot for blob {blobBlockClient.Uri.ToString()}. Exception{e.ToString()}");
361+
Trace.WriteLine($"EXCEPTION:milliseconds={stopwatch.ElapsedMilliseconds}:CreateSnapshot: Failed to take the snapshot for blob {RemoveQueryString(blobBlockClient.Uri)}. Exception{e.ToString()}");
362362
return false;
363363
}
364364
}
@@ -429,7 +429,7 @@ protected override async Task OnDeleteAsync(Uri resourceUri, DeleteRequestOption
429429

430430
public override Uri GetUri(string name)
431431
{
432-
var baseUri = _directory.Uri.AbsoluteUri;
432+
var baseUri = RemoveQueryString(_directory.Uri);
433433

434434
if (baseUri.EndsWith("/"))
435435
{
@@ -465,22 +465,22 @@ public async Task<bool> AreSynchronized(ICloudBlockBlob sourceBlockBlob, ICloudB
465465
var destinationBlobHasSha512Hash = destinationBlobMetadata.TryGetValue(Sha512HashAlgorithmId, out var destinationBlobSha512Hash);
466466
if (!sourceBlobHasSha512Hash)
467467
{
468-
Trace.TraceWarning($"The source blob ({sourceBlockBlob.Uri}) doesn't have the SHA512 hash.");
468+
Trace.TraceWarning($"The source blob ({RemoveQueryString(sourceBlockBlob.Uri)}) doesn't have the SHA512 hash.");
469469
}
470470
if (!destinationBlobHasSha512Hash)
471471
{
472-
Trace.TraceWarning($"The destination blob ({destinationBlockBlob.Uri}) doesn't have the SHA512 hash.");
472+
Trace.TraceWarning($"The destination blob ({RemoveQueryString(destinationBlockBlob.Uri)}) doesn't have the SHA512 hash.");
473473
}
474474
if (sourceBlobHasSha512Hash && destinationBlobHasSha512Hash)
475475
{
476476
if (sourceBlobSha512Hash == destinationBlobSha512Hash)
477477
{
478-
Trace.WriteLine($"The source blob ({sourceBlockBlob.Uri}) and destination blob ({destinationBlockBlob.Uri}) have the same SHA512 hash and are synchronized.");
478+
Trace.WriteLine($"The source blob ({RemoveQueryString(sourceBlockBlob.Uri)}) and destination blob ({RemoveQueryString(destinationBlockBlob.Uri)}) have the same SHA512 hash and are synchronized.");
479479
return true;
480480
}
481481

482482
// The SHA512 hash between the source and destination blob should be always same.
483-
Trace.TraceWarning($"The source blob ({sourceBlockBlob.Uri}) and destination blob ({destinationBlockBlob.Uri}) have the different SHA512 hash and are not synchronized. " +
483+
Trace.TraceWarning($"The source blob ({RemoveQueryString(sourceBlockBlob.Uri)}) and destination blob ({RemoveQueryString(destinationBlockBlob.Uri)}) have the different SHA512 hash and are not synchronized. " +
484484
$"The source blob hash is {sourceBlobSha512Hash} while the destination blob hash is {destinationBlobSha512Hash}");
485485
}
486486

@@ -524,7 +524,7 @@ public async Task<bool> HasPropertiesAsync(Uri blobUri, string contentType, stri
524524
private BlockBlobClient GetBlockBlobReference(string blobName)
525525
{
526526
IBlobContainerClientWrapper containerClient = _directory.ContainerClientWrapper;
527-
BlockBlobClient blobClient = containerClient.GetBlockBlobClient(blobName);
527+
BlockBlobClient blobClient = containerClient.GetBlockBlobClient(_directory.DirectoryPrefix + "/" + blobName);
528528

529529
// ApplyBlobRequestOptions(blobClient) is not needed as the options should be set at the client level
530530
// when creating the BlobServiceClient or BlobContainerClient.

src/Catalog/Persistence/AzureStorageBlobs.cs

Lines changed: 0 additions & 182 deletions
This file was deleted.

src/Catalog/Persistence/CloudBlobDirectoryWrapper.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -19,12 +19,12 @@ public class CloudBlobDirectoryWrapper : ICloudBlobDirectory
1919
private readonly BlobClientOptions _defaultClientOptions;
2020

2121
public BlobServiceClient ServiceClient => _containerClient.GetParentBlobServiceClient();
22-
public Uri Uri => new Uri(_containerClient.Uri, _directoryPrefix);
22+
public Uri Uri { get; }
2323
public string DirectoryPrefix => _directoryPrefix;
2424
public BlobClientOptions ContainerOptions => _defaultClientOptions;
2525
public IBlobContainerClientWrapper ContainerClientWrapper => _blobContainerClientWrapper;
2626

27-
public CloudBlobDirectoryWrapper(BlobServiceClient serviceClient, string containerName, string directoryPrefix, BlobClientOptions blobClientOptions = null)
27+
public CloudBlobDirectoryWrapper(BlobServiceClient serviceClient, string containerName, string directoryPrefix, BlobClientOptions blobClientOptions = null)
2828
{
2929
_directoryPrefix = directoryPrefix ?? throw new ArgumentNullException(nameof(directoryPrefix));
3030

@@ -48,7 +48,9 @@ public CloudBlobDirectoryWrapper(BlobServiceClient serviceClient, string contain
4848
{
4949
_containerClient = serviceClient.GetBlobContainerClient(containerName);
5050
}
51-
51+
52+
Uri = new Uri(Storage.RemoveQueryString(_containerClient.Uri).TrimEnd('/') + "/" + _directoryPrefix);
53+
5254
_blobContainerClientWrapper = new BlobContainerClientWrapper(_containerClient);
5355
}
5456

src/Catalog/Persistence/Storage.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -233,6 +233,11 @@ protected void TraceMethod(string method, Uri resourceUri)
233233
}
234234
}
235235

236+
public static string RemoveQueryString(Uri storageUri)
237+
{
238+
return storageUri.GetLeftPart(UriPartial.Path);
239+
}
240+
236241
private string TraceException(string method, Uri resourceUri, Exception exception)
237242
{
238243
string message = $"{method} EXCEPTION: {GetUri(GetName(resourceUri))} {exception.ToString()}";
@@ -246,4 +251,4 @@ private void TraceExecutionTime(string method, Uri resourceUri, long executionTi
246251
Trace.WriteLine(message);
247252
}
248253
}
249-
}
254+
}

0 commit comments

Comments
 (0)