예제 #1
0
        public void TestAffinityRun()
        {
            const string cacheName = DefaultCacheName;

            // Test keys for non-client nodes
            var nodes = new[] { _grid1, _grid2 }.Select(x => x.GetCluster().GetLocalNode());

            var aff = _grid1.GetAffinity(cacheName);

            foreach (var node in nodes)
            {
                var primaryKey = TestUtils.GetPrimaryKey(_grid1, cacheName, node);

                var affinityKey = aff.GetAffinityKey <int, int>(primaryKey);

                var computeAction = new ComputeAction
                {
                    ReservedPartition = aff.GetPartition(primaryKey),
                    CacheNames        = new[] { cacheName }
                };

                _grid1.GetCompute().AffinityRun(cacheName, affinityKey, computeAction);
                Assert.AreEqual(node.Id, ComputeAction.LastNodeId);

                _grid1.GetCompute().AffinityRunAsync(cacheName, affinityKey, computeAction).Wait();
                Assert.AreEqual(node.Id, ComputeAction.LastNodeId);
            }
        }
예제 #2
0
        /// <summary>
        /// Perform test operations.
        /// </summary>
        /// <param name="testNode">Owner of preloaded partition.</param>
        /// <param name="execNode">Node on which operation will be executed.</param>
        /// <param name="preloadMode">Preload mode <see cref="PreloadMode"/></param>
        private void PerformPreloadTest(IIgnite testNode, IIgnite execNode, PreloadMode preloadMode)
        {
            int key         = TestUtils.GetPrimaryKey(testNode, PersistenceCacheName);
            var affinity    = execNode.GetAffinity(PersistenceCacheName);
            int preloadPart = affinity.GetPartition(key);

            using (var streamer = execNode.GetDataStreamer <int, int>(PersistenceCacheName))
            {
                int cnt = EntriesCount;
                int k   = 0;

                while (cnt > 0)
                {
                    if (affinity.GetPartition(k) == preloadPart)
                    {
                        streamer.AddData(k, k);

                        cnt--;
                    }

                    k++;
                }
            }

            // Wait for checkpoint (wait for doubled CheckpointFrequency interval).
            Thread.Sleep(CheckpointFrequency.Add(CheckpointFrequency));

            switch (preloadMode)
            {
            case PreloadMode.Sync:
                execNode.GetCache <int, int>(PersistenceCacheName).PreloadPartition(preloadPart);

                break;

            case PreloadMode.Async:
                var task = execNode.GetCache <int, int>(PersistenceCacheName).PreloadPartitionAsync(preloadPart);

                task.WaitResult();

                break;

            case PreloadMode.Local:
                // In local mode we should load partition from testNode.
                bool res = testNode.GetCache <int, int>(PersistenceCacheName).LocalPreloadPartition(preloadPart);

                Assert.IsTrue(res);

                break;
            }


            long pagesRead = testNode.GetDataRegionMetrics(PersistenceRegionName).PagesRead;

            var entries = testNode.GetCache <int, int>(PersistenceCacheName).GetLocalEntries().ToList();

            Assert.AreEqual(entries.Count, EntriesCount);
            Assert.AreEqual(pagesRead, testNode.GetDataRegionMetrics(PersistenceRegionName).PagesRead);
        }
예제 #3
0
        /// <summary>
        /// Gets the primary keys.
        /// </summary>
        public static IEnumerable <int> GetPrimaryKeys(IIgnite ignite, string cacheName,
                                                       IClusterNode node = null)
        {
            var aff = ignite.GetAffinity(cacheName);

            node = node ?? ignite.GetCluster().GetLocalNode();

            return(Enumerable.Range(1, int.MaxValue).Where(x => aff.IsPrimary(node, x)));
        }
예제 #4
0
        /// <summary>
        /// Gets the primary partition keys.
        /// </summary>
        private static int[] GetPrimaryPartitionKeys(IIgnite ignite, int count)
        {
            var affinity = ignite.GetAffinity(CacheName);

            var localNode = ignite.GetCluster().GetLocalNode();

            var part = affinity.GetPrimaryPartitions(localNode).First();

            return(Enumerable.Range(0, int.MaxValue)
                   .Where(k => affinity.GetPartition(k) == part)
                   .Take(count)
                   .ToArray());
        }
예제 #5
0
        public void TestAffinity()
        {
            IIgnite g = Ignition.GetIgnite("grid-0");

            ICacheAffinity aff = g.GetAffinity("default");

            IClusterNode node = aff.MapKeyToNode(new AffinityTestKey(0, 1));

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(node.Id, aff.MapKeyToNode(new AffinityTestKey(i, 1)).Id);
            }
        }
예제 #6
0
        public void TestAffinityBinary()
        {
            IIgnite g = Ignition.GetIgnite("grid-0");

            ICacheAffinity aff = g.GetAffinity("default");

            IBinaryObject affKey = g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(0, 1));

            IClusterNode node = aff.MapKeyToNode(affKey);

            for (int i = 0; i < 10; i++)
            {
                IBinaryObject otherAffKey =
                    g.GetBinary().ToBinary <IBinaryObject>(new AffinityTestKey(i, 1));

                Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id);
            }
        }
예제 #7
0
        /// <summary>
        /// Checks affinity mapping.
        /// </summary>
        private static void TestAffinityKeyMappedWithQueryEntity0(IIgnite ignite, string cacheName)
        {
            var aff = ignite.GetAffinity(cacheName);

            var key1 = new QueryEntityKey {
                Data = "data1", AffinityKey = 1
            };
            var key2 = new QueryEntityKey {
                Data = "data2", AffinityKey = 1
            };

            var val1 = new QueryEntityValue {
                Name = "foo", AffKey = 100
            };
            var val2 = new QueryEntityValue {
                Name = "bar", AffKey = 100
            };

            Assert.AreEqual(aff.GetPartition(key1), aff.GetPartition(key2));
            Assert.AreEqual(aff.GetPartition(val1), aff.GetPartition(val2));
        }
예제 #8
0
 /** <inheritdoc /> */
 public ICacheAffinity GetAffinity(string name)
 {
     return(_ignite.GetAffinity(name));
 }