Пример #1
0
        private void CleanUpFields()
        {
            _logger.LogDebug("Searching for items to clean up.");
            var currTickCount = Environment.TickCount;
            var toRemove      = Shield.InTransaction(() =>
                                                     _freshIndex
                                                     .Where(i => i.Item.RemovableSince.HasValue
                        ? unchecked (currTickCount - i.Item.RemovableSince.Value) > Configuration.RemovableItemLingerMs
                        : i.Item.ExpiresInMs <= 0)
                                                     .Select(i => i.Item)
                                                     .ToArray());

            _logger.LogDebug("Found {ToRemoveCount} items to clean up.", toRemove.Length);
            Shield.InTransaction(() =>
            {
                foreach (var item in toRemove)
                {
                    if (_local.TryGetValue(item.Key, out var mi) && mi == item)
                    {
                        if (item.RemovableSince.HasValue)
                        {
                            _local.Remove(item.Key);
                        }
                        else
                        {
                            Expire(item);
                        }
                    }
                }
            });
        }
Пример #2
0
        private TimerCallback GetDeletableTimerMethod()
        {
            var lockObj = new object();

            return(_ =>
            {
                bool lockTaken = false;
                try
                {
                    Monitor.TryEnter(lockObj, ref lockTaken);
                    if (!lockTaken)
                    {
                        return;
                    }
                    var currTickCount = Environment.TickCount;
                    var toRemove = Shield.InTransaction(() =>
                                                        _freshIndex
                                                        .Where(i => i.Item.RemovableSince.HasValue
                                ? unchecked (currTickCount - i.Item.RemovableSince.Value) > Configuration.RemovableItemLingerMs
                                : i.Item.ExpiresInMs <= 0)
                                                        .Select(i => i.Item)
                                                        .ToArray());
                    Shield.InTransaction(() =>
                    {
                        foreach (var item in toRemove)
                        {
                            if (_local.TryGetValue(item.Key, out var mi) && mi == item)
                            {
                                if (item.RemovableSince.HasValue)
                                {
                                    _local.Remove(item.Key);
                                }
                                else
                                {
                                    Expire(item);
                                }
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    RaiseError(new GossipBackendException("Unexpected error on deletable timer task.", ex));
                }
                finally
                {
                    if (lockTaken)
                    {
                        Monitor.Exit(lockObj);
                    }
                }
            });
        }
Пример #3
0
        private static void ReadItemsShielded(ShieldedDictNc <long, object> ld, int iterations)
        {
            var sp = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                object value;
                ld.TryGetValue(i, out value);
            }

            Console.WriteLine(sp.Elapsed + " Reading values Shielded dictionary");
        }
Пример #4
0
        private static void ReadItemsShielded(ShieldedDictNc<long, object> ld, int iterations)
        {
            var sp = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                object value;
                ld.TryGetValue(i, out value);
            }

            Console.WriteLine(sp.Elapsed + " Reading values Shielded dictionary");
        }