Skip to content

Commit b088e24

Browse files
committed
Bitmask match instead of 'random'
1 parent f799eb8 commit b088e24

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ These settings are common across all plugins, although different implementations
5959
| `$(MSBuildCacheMaxConcurrentCacheContentOperations)` | `int` | 64 | The maximum number of cache operations to perform concurrently |
6060
| `$(MSBuildCacheLocalCacheRootPath)` | `string` | "\MSBuildCache" (in repo's drive root) | Base directory to use for the local cache. |
6161
| `$(MSBuildCacheLocalCacheSizeInMegabytes)` | `int` | 102400 (100 GB) | The maximum size in megabytes of the local cache |
62-
| `$(MSBuildCacheRandomlyForceCacheMissBitMask)` | `int` | 0 | Force a cache miss if the all the specified bits in project hash are set. Because the project hash is stable given the same inputs, building the same commit with the same bitmask will cause the same projects to be forced to miss. For example, 1, 2, 4, 8,... will each cause ~50% cache misses they are represented by one bit. Since they are different bits, changing from 1 to 2 will cause a different set of ~50% to miss. 3, 5, 6, ... will each cause ~25%. 7, 15, .. will each cause ~12%. Useful for testing to simulate natural cache misses. |
62+
| `$(MSBuildCacheForceCacheMissBitMask)` | `int` | 0 | Force a cache miss if the all the specified bits in project hash are set. Because the project hash is stable given the same inputs, building the same commit with the same bitmask will cause the same projects to be forced to miss. For example, 1, 2, 4, 8,... will each cause ~50% cache misses they are represented by one bit. Since they are different bits, changing from 1 to 2 will cause a different set of ~50% to miss. 3, 5, 6, ... will each cause ~25%. 7, 15, .. will each cause ~12%. Useful for testing to simulate natural cache misses. |
6363
| `$(MSBuildCacheIgnoredInputPatterns)` | `Glob[]` | | Files which are part of the repo which should be ignored for cache invalidation |
6464
| `$(MSBuildCacheIgnoredOutputPatterns)` | `Glob[]` | `*.assets.cache; *assemblyreference.cache` | Files to ignore for output collection into the cache. Note that if output are ignored, the replayed cache entry will not have these files. This should be used for intermediate outputs which are not properly portable |
6565
| `$(MSBuildCacheIdenticalDuplicateOutputPatterns)` | `Glob[]` | | Files to allow duplicate outputs, with identical content, across projects. Projects which produce files at the same path with differing content will still produce an error. Note: this setting should be used sparingly as it impacts performance |

src/Common.Tests/PluginSettingsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ public void LocalCacheSizeInMegabytesSetting()
9595
new[] { 123u, 456u, 789u });
9696

9797
[TestMethod]
98-
public void RandomlyForceCacheMissBitMaskSetting()
98+
public void ForceCacheMissBitMaskSetting()
9999
=> TestBasicSetting(
100-
nameof(PluginSettings.RandomlyForceCacheMissBitMask),
101-
pluginSettings => pluginSettings.RandomlyForceCacheMissBitMask,
100+
nameof(PluginSettings.ForceCacheMissBitMask),
101+
pluginSettings => pluginSettings.ForceCacheMissBitMask,
102102
new[] { 0u, 10u, 100u });
103103

104104
private static IEnumerable<object[]> GlobTestData

src/Common/MSBuildCachePluginBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,17 @@ private async Task<CacheResult> GetCacheResultInnerAsync(BuildRequestData buildR
349349
return CacheResult.IndicateNonCacheHit(CacheResultType.CacheMiss);
350350
}
351351

352-
if (Settings.RandomlyForceCacheMissBitMask != 0)
352+
if (Settings.ForceCacheMissBitMask != 0)
353353
{
354354
// use a hash of the project id so that it is repeatable
355355
#pragma warning disable CA1850 // ComputeHash is not in net472
356356
using SHA256 hasher = SHA256.Create();
357357
byte[] projectHash = hasher.ComputeHash(Encoding.UTF8.GetBytes(nodeContext.Id));
358358
uint hashInt = BitConverter.ToUInt32(projectHash, 0);
359359
#pragma warning restore CA1850
360-
if ((hashInt & Settings.RandomlyForceCacheMissBitMask) == Settings.RandomlyForceCacheMissBitMask)
360+
if ((hashInt & Settings.ForceCacheMissBitMask) == Settings.ForceCacheMissBitMask)
361361
{
362+
logger.LogMessage($"Forcing an otherwise 'cache hit' to be a 'cache miss' because of ForceCacheMissBitMask matches `{nodeContext.Id}`.");
362363
Interlocked.Increment(ref _cacheMissCount);
363364
return CacheResult.IndicateNonCacheHit(CacheResultType.CacheMiss);
364365
}

src/Common/PluginSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public string LocalCacheRootPath
8181

8282
public uint LocalCacheSizeInMegabytes { get; init; } = 102400; // 100GB
8383

84-
public uint RandomlyForceCacheMissBitMask { get; init; }
84+
public uint ForceCacheMissBitMask { get; init; }
8585

8686
public IReadOnlyCollection<Glob> IgnoredInputPatterns { get; init; } = Array.Empty<Glob>();
8787

src/Common/build/Microsoft.MSBuildCache.Common.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheMaxConcurrentCacheContentOperations</MSBuildCacheGlobalPropertiesToIgnore>
1111
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheLocalCacheRootPath</MSBuildCacheGlobalPropertiesToIgnore>
1212
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheLocalCacheSizeInMegabytes</MSBuildCacheGlobalPropertiesToIgnore>
13-
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheRandomlyForceCacheMissBitMask</MSBuildCacheGlobalPropertiesToIgnore>
13+
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheForceCacheMissBitMask</MSBuildCacheGlobalPropertiesToIgnore>
1414
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheIgnoredInputPatterns</MSBuildCacheGlobalPropertiesToIgnore>
1515
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheIgnoredOutputPatterns</MSBuildCacheGlobalPropertiesToIgnore>
1616
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheIdenticalDuplicateOutputPatterns</MSBuildCacheGlobalPropertiesToIgnore>
@@ -30,7 +30,7 @@
3030
<MaxConcurrentCacheContentOperations>$(MSBuildCacheMaxConcurrentCacheContentOperations)</MaxConcurrentCacheContentOperations>
3131
<LocalCacheRootPath>$(MSBuildCacheLocalCacheRootPath)</LocalCacheRootPath>
3232
<LocalCacheSizeInMegabytes>$(MSBuildCacheLocalCacheSizeInMegabytes)</LocalCacheSizeInMegabytes>
33-
<RandomlyForceCacheMissBitMask>$(MSBuildCacheRandomlyForceCacheMissBitMask)</RandomlyForceCacheMissBitMask>
33+
<ForceCacheMissBitMask>$(MSBuildCacheForceCacheMissBitMask)</ForceCacheMissBitMask>
3434
<IgnoredInputPatterns>$(MSBuildCacheIgnoredInputPatterns)</IgnoredInputPatterns>
3535
<IgnoredOutputPatterns>$(MSBuildCacheIgnoredOutputPatterns)</IgnoredOutputPatterns>
3636
<IdenticalDuplicateOutputPatterns>$(MSBuildCacheIdenticalDuplicateOutputPatterns)</IdenticalDuplicateOutputPatterns>

0 commit comments

Comments
 (0)