Exemple #1
0
 public async ValueTask <NearCache> GetOrCreateNearCacheAsync(string name, NearCacheOptions options, CancellationToken cancellationToken = default)
 {
     return(await _caches.GetOrAddAsync(name, async (n, token) =>
     {
         var nearCache = new NearCache(n, _cluster, _serializationService, _loggerFactory, options, GetMaxToleratedMissCount());
         await InitializeNearCache(nearCache).CfAwait();
         return nearCache;
     }, cancellationToken).CfAwait());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RepairingHandler"/> class.
 /// </summary>
 /// <param name="clusterClientId">The unique identifier of the cluster, as assigned by the client.</param>
 /// <param name="nearCache">The near cache instance.</param>
 /// <param name="maxToleratedMissCount">The max tolerated miss count.</param>
 /// <param name="partitioner">The partitioner.</param>
 /// <param name="serializationService">The serialization service.</param>
 /// <param name="loggerFactory">A logger factory.</param>
 public RepairingHandler(Guid clusterClientId, NearCache nearCache, int maxToleratedMissCount, Partitioner partitioner, ISerializationService serializationService, ILoggerFactory loggerFactory)
 {
     _clusterClientId       = clusterClientId;
     _nearCache             = nearCache;
     _partitioner           = partitioner;
     _partitionCount        = partitioner.Count;
     _metadataTable         = CreateMetadataTable(_partitionCount);
     _maxToleratedMissCount = maxToleratedMissCount;
     _serializationService  = serializationService;
     _logger = loggerFactory.CreateLogger <RepairingHandler>();
 }
Exemple #3
0
        private async ValueTask InitializeNearCache(NearCache nearCache)
        {
            await nearCache.InitializeAsync().CfAwait();

            if (!nearCache.IsInvalidating)
            {
                return;
            }

            var repairingHandler = nearCache.RepairingHandler;

            if (repairingHandler == null)
            {
                return;                           // though that should never happen
            }
            // initialize
            await foreach (var(member, metadata) in FetchMetadataAsync(new[] { nearCache.Name }))
            {
                try
                {
                    repairingHandler.InitializeGuids(metadata.PartitionUuidList);
                    repairingHandler.InitializeSequences(metadata.NamePartitionSequenceList);
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e, $"An exception was thrown while processing invalidation meta data from address {member.Address}.");
                }
            }

            // start repairing task if not started
            if (Interlocked.CompareExchange(ref _running, 1, 0) == 0)
            {
                _repairingCancellation = new CancellationTokenSource();
                _repairing             = Repair(_repairingCancellation.Token).AsTask();

                Interlocked.Exchange(ref _lastAntiEntropyRunMillis, Clock.Milliseconds);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NearCache{TValue}"/> class.
 /// </summary>
 /// <param name="cache">A non-typed Near Cache.</param>
 public NearCache(NearCache cache)
 {
     InnerCache = cache;
 }