示例#1
0
        public string this[string depending]
        {
            set
            {
                if (depending == value)
                {
                    //do nothing because self-dependencies are not useful
                    //and they interfere with calculation of degree
                    return;
                }
                var row    = TokenMap.GetIndex(depending);
                var column = TokenMap.GetIndex(value);

                var adjacencyEntryNotSet = this[row, column].CoerceZero() == 0d;

                if (adjacencyEntryNotSet)
                {
                    //increase degree
                    this [row, row] = this [row, row] + 1.0d;

                    //increment adjacency
                    //(inverted to allow use without further processing)
                    this[row, column] = this [row, column] - 1.0d;
                }
                //else do nothing because this is not a multigraph
            }
        }
示例#2
0
        public void TokenMap_IsDoneForToken_Should_Return_False_When_Not_Satisfied()
        {
            var ksReplicationFactor = new Dictionary <string, int>
            {
                { "dc1", 1 },
                { "dc2", 3 },
                { "dc3", 1 }
            };
            var replicasByDc = new Dictionary <string, int>
            {
                { "dc1", 1 },
                { "dc2", 1 }
            };
            //no host in DC 3
            var datacenters = new Dictionary <string, DatacenterInfo>
            {
                { "dc1", new DatacenterInfo {
                      HostLength = 10
                  } },
                { "dc2", new DatacenterInfo {
                      HostLength = 10
                  } }
            };

            Assert.False(TokenMap.IsDoneForToken(ksReplicationFactor, replicasByDc, datacenters));
        }
示例#3
0
        public void TokenMapSimpleStrategyWithKeyspaceTest()
        {
            var rp    = new ConstantReconnectionPolicy(1);
            var hosts = new List <Host>
            {
                { TestHelper.CreateHost("192.168.0.0", "dc1", "rack", new HashSet <string> {
                        "0"
                    }) },
                { TestHelper.CreateHost("192.168.0.1", "dc1", "rack", new HashSet <string> {
                        "10"
                    }) },
                { TestHelper.CreateHost("192.168.0.2", "dc1", "rack", new HashSet <string> {
                        "20"
                    }) }
            };
            const string strategy  = ReplicationStrategies.SimpleStrategy;
            var          keyspaces = new List <KeyspaceMetadata>
            {
                new KeyspaceMetadata(null, "ks1", true, strategy, new Dictionary <string, int> {
                    { "replication_factor", 2 }
                }),
                new KeyspaceMetadata(null, "ks2", true, strategy, new Dictionary <string, int> {
                    { "replication_factor", 10 }
                })
            };
            var tokenMap = TokenMap.Build("Murmur3Partitioner", hosts, keyspaces);

            //the primary replica and the next
            var replicas = tokenMap.GetReplicas("ks1", new M3PToken(0));

            Assert.AreEqual("0,1", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));
            replicas = tokenMap.GetReplicas("ks1", new M3PToken(-100));
            Assert.AreEqual("0,1", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));
            //Greater than the greatest token
            replicas = tokenMap.GetReplicas("ks1", new M3PToken(500000));
            Assert.AreEqual("0,1", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));

            //The next replica should be the first
            replicas = tokenMap.GetReplicas("ks1", new M3PToken(20));
            Assert.AreEqual("2,0", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));

            //The closest replica and the next
            replicas = tokenMap.GetReplicas("ks1", new M3PToken(19));
            Assert.AreEqual("2,0", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));

            //Even if the replication factor is greater than the ring, it should return only ring size
            replicas = tokenMap.GetReplicas("ks2", new M3PToken(5));
            Assert.AreEqual("1,2,0", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));

            //The primary replica only as the keyspace was not found
            replicas = tokenMap.GetReplicas(null, new M3PToken(0));
            Assert.AreEqual("0", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));
            replicas = tokenMap.GetReplicas(null, new M3PToken(10));
            Assert.AreEqual("1", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));
            replicas = tokenMap.GetReplicas("ks_does_not_exist", new M3PToken(20));
            Assert.AreEqual("2", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));
            replicas = tokenMap.GetReplicas(null, new M3PToken(19));
            Assert.AreEqual("2", String.Join(",", replicas.Select(TestHelper.GetLastAddressByte)));
        }
        public void TokenMap_IsDoneForToken_Should_Return_True_When_No_Host_In_Dc()
        {
            var ksReplicationFactor = new Dictionary <string, int>
            {
                { "dc1", 1 },
                { "dc2", 3 },
                { "dc3", 1 }
            };
            var replicasByDc = new Dictionary <string, int>
            {
                { "dc1", 1 },
                { "dc2", 3 }
            };
            //no host in DC 3
            var datacenters = new Dictionary <string, int>
            {
                { "dc1", 10 },
                { "dc2", 10 }
            };

            Assert.True(TokenMap.IsDoneForToken(ksReplicationFactor, replicasByDc, datacenters));
        }
示例#5
0
        public void TokenMap_Build_SimpleStrategy_Adjacent_Ranges_Test()
        {
            var hosts = new[]
            {
                //0 and 100 are adjacent
                TestHelper.CreateHost("192.168.0.1", "dc1", "rack1", new HashSet <string> {
                    "0", "100", "1000"
                }),
                TestHelper.CreateHost("192.168.0.2", "dc1", "rack1", new HashSet <string> {
                    "200", "2000", "20000"
                }),
                TestHelper.CreateHost("192.168.0.3", "dc1", "rack1", new HashSet <string> {
                    "300", "3000", "30000"
                })
            };
            var ks       = FakeSchemaParserFactory.CreateSimpleKeyspace("ks1", 2);
            var map      = TokenMap.Build("Murmur3Partitioner", hosts, new[] { ks });
            var replicas = map.GetReplicas("ks1", new M3PToken(0));

            Assert.AreEqual(2, replicas.Count);
            //It should contain the first host and the second, even though the first host contains adjacent
            CollectionAssert.AreEqual(new byte[] { 1, 2 }, replicas.Select(TestHelper.GetLastAddressByte));
        }
示例#6
0
 public IteratorAnonymousInnerClass(TokenMap outerInstance, IEnumerator <KeyValuePair <int, string> > iterator)
 {
     this.outerInstance = outerInstance;
     this._iterator     = iterator;
 }