private Task AssertExpirationInRangeAsync(Context context, string cacheNamespace, StrongFingerprint strongFingerprint, DateTime expectedLow, DateTime expectedHigh)
        {
            // Create a bare BuildCache client so that the value read is not thwarted by some intermediate cache layer (like Redis)
            Func <DisposableDirectory, ICache> createCheckerCacheFunc =
                dir => CreateBareBuildCache(dir, cacheNamespace, FileSystem, Logger, BackingOption.WriteThrough, ItemStorageOption);

            Func <ICacheSession, Task> checkFunc = async(ICacheSession checkSession) =>
            {
                // Bare BuildCache clients should only produce BuildCacheSessions
                BuildCacheSession buildCacheSession = checkSession as BuildCacheSession;
                Assert.NotNull(buildCacheSession);

                // Raw expiration is only visible to the adapter, not through the ICacheSession APIs.
                // This also has the nice (non-)side-effect of not updating the expiration as part of *this* read.
                IContentHashListAdapter buildCacheHttpClientAdapter       = buildCacheSession.ContentHashListAdapter;
                ObjectResult <ContentHashListWithCacheMetadata> getResult = await buildCacheHttpClientAdapter.GetContentHashListAsync(context, cacheNamespace, strongFingerprint);

                Assert.True(getResult.Succeeded);
                Assert.NotNull(getResult.Data);
                DateTime?rawExpiration = getResult.Data.GetRawExpirationTimeUtc();
                Assert.NotNull(rawExpiration);

                // Verify that the raw expiration (i.e. the value's TTL w/o consideration for content existence or whether the value might be replaced) is visible and correct
                TimeSpan assertionTolerance = TimeSpan.FromHours(1); // The test time + the simulator's clock skew hopefully won't exceed 1 hour.
                Assert.InRange(rawExpiration.Value, expectedLow - assertionTolerance, expectedHigh + assertionTolerance);
            };

            return(RunTestAsync(context, checkFunc, createCheckerCacheFunc));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildCacheSession"/> class.
 /// </summary>
 /// <param name="fileSystem">Filesystem used to read/write files.</param>
 /// <param name="name">Session name.</param>
 /// <param name="implicitPin">Policy determining whether or not content should be automatically pinned on adds or gets.</param>
 /// <param name="cacheNamespace">The namespace of the cache being communicated with.</param>
 /// <param name="cacheId">The id of the cache being communicated with.</param>
 /// <param name="contentHashListAdapter">Backing BuildCache http client.</param>
 /// <param name="backingContentSession">Backing BlobStore content session.</param>
 /// <param name="maxFingerprintSelectorsToFetch">Maximum number of selectors to enumerate for a GetSelectors call.</param>
 /// <param name="minimumTimeToKeepContentHashLists">Minimum time-to-live for created or referenced ContentHashLists.</param>
 /// <param name="rangeOfTimeToKeepContentHashLists">Range of time beyond the minimum for the time-to-live of created or referenced ContentHashLists.</param>
 /// <param name="fingerprintIncorporationEnabled">Feature flag to enable fingerprints incorporation</param>
 /// <param name="maxDegreeOfParallelismForIncorporateRequests">Throttle the number of fingerprints chunks sent in parallel</param>
 /// <param name="maxFingerprintsPerIncorporateRequest">Max fingerprints allowed per chunk</param>
 /// <param name="writeThroughContentSession">Optional write-through session to allow writing-behind to BlobStore</param>
 /// <param name="sealUnbackedContentHashLists">If true, the client will attempt to seal any unbacked ContentHashLists that it sees.</param>
 /// <param name="overrideUnixFileAccessMode">If true, overrides default Unix file access modes when placing files.</param>
 /// <param name="tracer">A tracer for logging calls</param>
 /// <param name="enableEagerFingerprintIncorporation"><see cref="BuildCacheServiceConfiguration.EnableEagerFingerprintIncorporation"/></param>
 /// <param name="inlineFingerprintIncorporationExpiry"><see cref="BuildCacheServiceConfiguration.InlineFingerprintIncorporationExpiryHours"/></param>
 /// <param name="eagerFingerprintIncorporationInterval"><see cref="BuildCacheServiceConfiguration.EagerFingerprintIncorporationNagleIntervalMinutes"/></param>
 /// <param name="eagerFingerprintIncorporationBatchSize"><see cref="BuildCacheServiceConfiguration.EagerFingerprintIncorporationNagleBatchSize"/></param>
 /// <param name="manuallyExtendContentLifetime">Whether to manually extend content lifetime when doing incorporate calls</param>
 /// <param name="forceUpdateOnAddContentHashList">Whether to force an update and ignore existing CHLs when adding.</param>
 public BuildCacheSession(
     IAbsFileSystem fileSystem,
     string name,
     ImplicitPin implicitPin,
     string cacheNamespace,
     Guid cacheId,
     IContentHashListAdapter contentHashListAdapter,
     IBackingContentSession backingContentSession,
     int maxFingerprintSelectorsToFetch,
     TimeSpan minimumTimeToKeepContentHashLists,
     TimeSpan rangeOfTimeToKeepContentHashLists,
     bool fingerprintIncorporationEnabled,
     int maxDegreeOfParallelismForIncorporateRequests,
     int maxFingerprintsPerIncorporateRequest,
     IContentSession writeThroughContentSession,
     bool sealUnbackedContentHashLists,
     bool overrideUnixFileAccessMode,
     BuildCacheCacheTracer tracer,
     bool enableEagerFingerprintIncorporation,
     TimeSpan inlineFingerprintIncorporationExpiry,
     TimeSpan eagerFingerprintIncorporationInterval,
     int eagerFingerprintIncorporationBatchSize,
     bool manuallyExtendContentLifetime,
     bool forceUpdateOnAddContentHashList)
     : base(
         fileSystem,
         name,
         implicitPin,
         cacheNamespace,
         cacheId,
         contentHashListAdapter,
         backingContentSession,
         maxFingerprintSelectorsToFetch,
         minimumTimeToKeepContentHashLists,
         rangeOfTimeToKeepContentHashLists,
         fingerprintIncorporationEnabled,
         maxDegreeOfParallelismForIncorporateRequests,
         maxFingerprintsPerIncorporateRequest,
         writeThroughContentSession,
         sealUnbackedContentHashLists,
         overrideUnixFileAccessMode,
         tracer,
         enableEagerFingerprintIncorporation,
         inlineFingerprintIncorporationExpiry,
         eagerFingerprintIncorporationInterval,
         eagerFingerprintIncorporationBatchSize,
         manuallyExtendContentLifetime,
         forceUpdateOnAddContentHashList)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="BuildCacheReadOnlySession"/> class.
        /// </summary>
        /// <param name="fileSystem">A interface to read/write files.</param>
        /// <param name="name">Session name.</param>
        /// <param name="implicitPin">Policy determining whether or not content should be automatically pinned on adds or gets.</param>
        /// <param name="cacheNamespace">the namespace of the cache in VSTS</param>
        /// <param name="cacheId">the guid of the cache in VSTS</param>
        /// <param name="contentHashListAdapter">Backing BuildCache http client.</param>
        /// <param name="backingContentSession">Backing content session.</param>
        /// <param name="maxFingerprintSelectorsToFetch">Maximum number of selectors to enumerate.</param>
        /// <param name="minimumTimeToKeepContentHashLists">Minimum time-to-live for created or referenced ContentHashLists.</param>
        /// <param name="rangeOfTimeToKeepContentHashLists">Range of time beyond the minimum for the time-to-live of created or referenced ContentHashLists.</param>
        /// <param name="fingerprintIncorporationEnabled">Feature flag to enable fingerprints incorporation</param>
        /// <param name="maxDegreeOfParallelismForIncorporateRequests">Throttle the number of fingerprints chunks sent in parallel</param>
        /// <param name="maxFingerprintsPerIncorporateRequest">Max fingerprints allowed per chunk</param>
        /// <param name="writeThroughContentSession">Optional write-through session to allow writing-behind to BlobStore</param>
        /// <param name="sealUnbackedContentHashLists">If true, the client will attempt to seal any unbacked ContentHashLists that it sees.</param>
        /// <param name="overrideUnixFileAccessMode">If true, overrides default Unix file access modes when placing files.</param>
        /// <param name="tracer">A tracer for logging and perf counters.</param>
        public BuildCacheReadOnlySession(
            IAbsFileSystem fileSystem,
            string name,
            ImplicitPin implicitPin,
            string cacheNamespace,
            Guid cacheId,
            IContentHashListAdapter contentHashListAdapter,
            IContentSession backingContentSession,
            int maxFingerprintSelectorsToFetch,
            TimeSpan minimumTimeToKeepContentHashLists,
            TimeSpan rangeOfTimeToKeepContentHashLists,
            bool fingerprintIncorporationEnabled,
            int maxDegreeOfParallelismForIncorporateRequests,
            int maxFingerprintsPerIncorporateRequest,
            IContentSession writeThroughContentSession,
            bool sealUnbackedContentHashLists,
            bool overrideUnixFileAccessMode,
            BuildCacheCacheTracer tracer)
        {
            Contract.Requires(name != null);
            Contract.Requires(contentHashListAdapter != null);
            Contract.Requires(backingContentSession != null);
            Contract.Requires(!backingContentSession.StartupStarted);

            Name                            = name;
            ImplicitPin                     = implicitPin;
            ContentHashListAdapter          = contentHashListAdapter;
            BackingContentSession           = backingContentSession;
            _maxFingerprintSelectorsToFetch = maxFingerprintSelectorsToFetch;
            CacheNamespace                  = cacheNamespace;
            CacheId                         = cacheId;
            WriteThroughContentSession      = writeThroughContentSession;
            _sealUnbackedContentHashLists   = sealUnbackedContentHashLists;
            Tracer                          = tracer;

            _tempDirectory = new DisposableDirectory(fileSystem);
            _sealingErrorsToPrintOnShutdown  = new List <string>();
            _fingerprintIncorporationEnabled = fingerprintIncorporationEnabled;
            _maxDegreeOfParallelismForIncorporateRequests = maxDegreeOfParallelismForIncorporateRequests;
            _maxFingerprintsPerIncorporateRequest         = maxFingerprintsPerIncorporateRequest;
            _overrideUnixFileAccessMode = overrideUnixFileAccessMode;

            FingerprintTracker = new FingerprintTracker(DateTime.UtcNow + minimumTimeToKeepContentHashLists, rangeOfTimeToKeepContentHashLists);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildCacheSession"/> class.
 /// </summary>
 /// <param name="fileSystem">Filesystem used to read/write files.</param>
 /// <param name="name">Session name.</param>
 /// <param name="implicitPin">Policy determining whether or not content should be automatically pinned on adds or gets.</param>
 /// <param name="cacheNamespace">The namespace of the cache being communicated with.</param>
 /// <param name="cacheId">The id of the cache being communicated with.</param>
 /// <param name="contentHashListAdapter">Backing BuildCache http client.</param>
 /// <param name="backingContentSession">Backing BlobStore content session.</param>
 /// <param name="maxFingerprintSelectorsToFetch">Maximum number of selectors to enumerate for a GetSelectors call.</param>
 /// <param name="minimumTimeToKeepContentHashLists">Minimum time-to-live for created or referenced ContentHashLists.</param>
 /// <param name="rangeOfTimeToKeepContentHashLists">Range of time beyond the minimum for the time-to-live of created or referenced ContentHashLists.</param>
 /// <param name="fingerprintIncorporationEnabled">Feature flag to enable fingerprints incorporation</param>
 /// <param name="maxDegreeOfParallelismForIncorporateRequests">Throttle the number of fingerprints chunks sent in parallel</param>
 /// <param name="maxFingerprintsPerIncorporateRequest">Max fingerprints allowed per chunk</param>
 /// <param name="writeThroughContentSession">Optional write-through session to allow writing-behind to BlobStore</param>
 /// <param name="sealUnbackedContentHashLists">If true, the client will attempt to seal any unbacked ContentHashLists that it sees.</param>
 /// <param name="overrideUnixFileAccessMode">If true, overrides default Unix file access modes when placing files.</param>
 /// <param name="tracer">A tracer for logging calls</param>
 public BuildCacheSession(
     IAbsFileSystem fileSystem,
     string name,
     ImplicitPin implicitPin,
     string cacheNamespace,
     Guid cacheId,
     IContentHashListAdapter contentHashListAdapter,
     IContentSession backingContentSession,
     int maxFingerprintSelectorsToFetch,
     TimeSpan minimumTimeToKeepContentHashLists,
     TimeSpan rangeOfTimeToKeepContentHashLists,
     bool fingerprintIncorporationEnabled,
     int maxDegreeOfParallelismForIncorporateRequests,
     int maxFingerprintsPerIncorporateRequest,
     IContentSession writeThroughContentSession,
     bool sealUnbackedContentHashLists,
     bool overrideUnixFileAccessMode,
     BuildCacheCacheTracer tracer)
     : base(
         fileSystem,
         name,
         implicitPin,
         cacheNamespace,
         cacheId,
         contentHashListAdapter,
         backingContentSession,
         maxFingerprintSelectorsToFetch,
         minimumTimeToKeepContentHashLists,
         rangeOfTimeToKeepContentHashLists,
         fingerprintIncorporationEnabled,
         maxDegreeOfParallelismForIncorporateRequests,
         maxFingerprintsPerIncorporateRequest,
         writeThroughContentSession,
         sealUnbackedContentHashLists,
         overrideUnixFileAccessMode,
         tracer)
 {
 }