Skip to content

Commit c886dc3

Browse files
authored
Fix bug where chunking could use different hash than the client (#4684)
* Use same hashtype as the dedupclient when generating the hashes * Delete unneeded factory class variable. ---------
1 parent b5e92c4 commit c886dc3

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/Microsoft.VisualStudio.Services.Agent/Blob/BlobStoreUtils.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public static class BlobStoreUtils
3333
bool enableReporting = false)
3434
{
3535
// Create chunks and identifier
36-
traceOutput(StringUtil.Loc("BuildingFileTree"));
37-
var fileNodes = await GenerateHashes(itemPaths, cancellationToken);
36+
traceOutput(StringUtil.Loc("BuildingFileTree"));
37+
var fileNodes = await GenerateHashes(itemPaths, dedupClient.HashType, cancellationToken);
3838
var rootNode = CreateNodeToUpload(fileNodes.Where(x => x.Success).Select(y => y.Node));
3939

4040
// If there are multiple paths to one DedupId (duplicate files)
@@ -111,7 +111,7 @@ private static Task StartReportingTask(Action<string> traceOutput, long totalByt
111111
});
112112
}
113113

114-
private static async Task<List<BlobFileInfo>> GenerateHashes(IReadOnlyList<string> filePaths, CancellationToken cancellationToken)
114+
private static async Task<List<BlobFileInfo>> GenerateHashes(IReadOnlyList<string> filePaths, HashType hashType, CancellationToken cancellationToken)
115115
{
116116
var nodes = new BlobFileInfo[filePaths.Count];
117117
var queue = NonSwallowingActionBlock.Create<int>(
@@ -120,7 +120,7 @@ private static async Task<List<BlobFileInfo>> GenerateHashes(IReadOnlyList<strin
120120
var itemPath = filePaths[i];
121121
try
122122
{
123-
var dedupNode = await ChunkerHelper.CreateFromFileAsync(FileSystem.Instance, itemPath, false, ChunkerHelper.DefaultChunkHashType, cancellationToken);
123+
var dedupNode = await ChunkerHelper.CreateFromFileAsync(FileSystem.Instance, itemPath, false, hashType, cancellationToken);
124124
nodes[i] = new BlobFileInfo
125125
{
126126
Path = itemPath,

src/Microsoft.VisualStudio.Services.Agent/Blob/DedupManifestArtifactClientFactory.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ public class DedupManifestArtifactClientFactory : IDedupManifestArtifactClientFa
9191
// At 192x it was around 16 seconds and 256x was no faster.
9292
private const int DefaultDedupStoreClientMaxParallelism = 192;
9393

94-
private HashType? HashType { get; set; }
95-
9694
public static readonly DedupManifestArtifactClientFactory Instance = new();
9795

9896
private DedupManifestArtifactClientFactory()
@@ -152,17 +150,17 @@ private DedupManifestArtifactClientFactory()
152150
IDedupStoreHttpClient dedupStoreHttpClient = GetDedupStoreHttpClient(connection, domainId, maxRetries, tracer, cancellationToken);
153151

154152
var telemetry = new BlobStoreClientTelemetry(tracer, dedupStoreHttpClient.BaseAddress);
155-
this.HashType = clientSettings.GetClientHashType(context);
153+
HashType hashType= clientSettings.GetClientHashType(context);
156154

157-
if (this.HashType == BuildXL.Cache.ContentStore.Hashing.HashType.Dedup1024K)
155+
if (hashType == BuildXL.Cache.ContentStore.Hashing.HashType.Dedup1024K)
158156
{
159157
dedupStoreHttpClient.RecommendedChunkCountPerCall = 10; // This is to workaround IIS limit - https://learn.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/requestlimits/
160158
}
161-
traceOutput($"Hashtype: {this.HashType.Value}");
159+
traceOutput($"Hashtype: {hashType}");
162160

163161
dedupStoreHttpClient.SetRedirectTimeout(clientSettings.GetRedirectTimeout());
164162

165-
var dedupClient = new DedupStoreClientWithDataport(dedupStoreHttpClient, new DedupStoreClientContext(maxParallelism), this.HashType.Value);
163+
var dedupClient = new DedupStoreClientWithDataport(dedupStoreHttpClient, new DedupStoreClientContext(maxParallelism), hashType);
166164
return (new DedupManifestArtifactClient(telemetry, dedupClient, tracer), telemetry);
167165
}
168166

@@ -222,6 +220,7 @@ private static IDedupStoreHttpClient GetDedupStoreHttpClient(VssConnection conne
222220
dedupStoreHttpClient.SetRedirectTimeout(redirectTimeoutSeconds);
223221
var telemetry = new BlobStoreClientTelemetryTfs(tracer, dedupStoreHttpClient.BaseAddress, connection);
224222
var client = new DedupStoreClient(dedupStoreHttpClient, maxParallelism);
223+
traceOutput($" - Hash type: {client.HashType}");
225224
return (client, telemetry);
226225
}
227226

0 commit comments

Comments
 (0)