Пример #1
0
        ICassandraReplicationStrategy GetReplicationStrategy(IConfiguration configuration)
        {
            var replStratefyCfg = configuration["cronus_projections_cassandra_replication_strategy"];
            var replFactorCfg   = configuration["cronus_projections_cassandra_replication_factor"];

            ICassandraReplicationStrategy replicationStrategy = null;

            if (string.IsNullOrEmpty(replStratefyCfg))
            {
                replicationStrategy = new SimpleReplicationStrategy(1);
            }
            else if (replStratefyCfg.Equals("simple", StringComparison.OrdinalIgnoreCase))
            {
                replicationStrategy = new SimpleReplicationStrategy(GetReplicationFactor(configuration));
            }
            else if (replStratefyCfg.Equals("network_topology", StringComparison.OrdinalIgnoreCase))
            {
                int      replicationFactor = GetReplicationFactor(configuration);
                var      settings          = new List <NetworkTopologyReplicationStrategy.DataCenterSettings>();
                string[] datacenters       = configuration["cronus_projections_cassandra__datacenters"].Split(',');
                foreach (var datacenter in datacenters)
                {
                    var setting = new NetworkTopologyReplicationStrategy.DataCenterSettings(datacenter, replicationFactor);
                    settings.Add(setting);
                }
                replicationStrategy = new NetworkTopologyReplicationStrategy(settings);
            }

            return(replicationStrategy);
        }
        public void TestUpdateKeyspaceWithMultiDcConfiguration()
        {
            var clusterConnection = cluster.RetrieveClusterConnection();

            var keyspaceName    = TestSchemaUtils.GetRandomKeyspaceName();
            var createdKeyspace = new Keyspace
            {
                Name = keyspaceName,
                ReplicationStrategy = NetworkTopologyReplicationStrategy.Create(new[]
                {
                    new DataCenterReplicationFactor("dc1", 3),
                    new DataCenterReplicationFactor("dc2", 5)
                })
            };

            clusterConnection.AddKeyspace(createdKeyspace);

            createdKeyspace.ReplicationStrategy = NetworkTopologyReplicationStrategy.Create(new[]
            {
                new DataCenterReplicationFactor("dc3", 7)
            });
            clusterConnection.UpdateKeyspace(createdKeyspace);

            var keyspaces      = clusterConnection.RetrieveKeyspaces();
            var actualKeyspace = keyspaces.First(x => x.Name == keyspaceName);

            AssertKeyspacePropertiesEquals(createdKeyspace, actualKeyspace);
        }
Пример #3
0
        internal ICassandraReplicationStrategy GetReplicationStrategy()
        {
            ICassandraReplicationStrategy replicationStrategy = null;

            if (options.ReplicationStrategy.Equals("simple", StringComparison.OrdinalIgnoreCase))
            {
                replicationStrategy = new SimpleReplicationStrategy(options.ReplicationFactor);
            }
            else if (options.ReplicationStrategy.Equals("network_topology", StringComparison.OrdinalIgnoreCase))
            {
                var settings = new List <NetworkTopologyReplicationStrategy.DataCenterSettings>();
                foreach (var datacenter in options.Datacenters)
                {
                    var setting = new NetworkTopologyReplicationStrategy.DataCenterSettings(datacenter, options.ReplicationFactor);
                    settings.Add(setting);
                }
                replicationStrategy = new NetworkTopologyReplicationStrategy(settings);
            }

            return(replicationStrategy);
        }
        public void TestUpdateKeyspace(bool durableWrites)
        {
            var keyspaceName = Guid.NewGuid().ToString("N");

            cassandraCluster.ActualizeKeyspaces(new[]
            {
                new KeyspaceScheme
                {
                    Name          = keyspaceName,
                    Configuration = new KeyspaceConfiguration
                    {
                        DurableWrites       = durableWrites,
                        ReplicationStrategy = SimpleReplicationStrategy.Create(1),
                        ColumnFamilies      = new[]
                        {
                            new ColumnFamily
                            {
                                Name = "1"
                            },
                            new ColumnFamily
                            {
                                Name = "2"
                            },
                            new ColumnFamily
                            {
                                Name = "3"
                            }
                        }
                    }
                }
            });

            var keyspaces = cassandraCluster.RetrieveClusterConnection().RetrieveKeyspaces().ToArray();

            AssertKeyspacesEquals(new Keyspace
            {
                Name                = keyspaceName,
                DurableWrites       = durableWrites,
                ReplicationStrategy = SimpleReplicationStrategy.Create(1),
                ColumnFamilies      = new Dictionary <string, ColumnFamily>
                {
                    { "1", new ColumnFamily {
                          Name = "1"
                      } },
                    { "2", new ColumnFamily {
                          Name = "2"
                      } },
                    { "3", new ColumnFamily {
                          Name = "3"
                      } }
                }
            }, keyspaces.Single(keyspace1 => keyspace1.Name == keyspaceName));

            cassandraCluster.RetrieveClusterConnection().UpdateKeyspace(new Keyspace
            {
                Name                = keyspaceName,
                DurableWrites       = durableWrites,
                ReplicationStrategy = NetworkTopologyReplicationStrategy.Create(new[] { new DataCenterReplicationFactor("dc1", 3) })
            });

            var keyspace = cassandraCluster.RetrieveClusterConnection().RetrieveKeyspaces().ToArray().Single(keyspace1 => keyspace1.Name == keyspaceName);

            AssertKeyspacesEquals(new Keyspace
            {
                Name                = keyspaceName,
                DurableWrites       = durableWrites,
                ReplicationStrategy = NetworkTopologyReplicationStrategy.Create(new[] { new DataCenterReplicationFactor("dc1", 3) }),
                ColumnFamilies      = new Dictionary <string, ColumnFamily>
                {
                    { "1", new ColumnFamily {
                          Name = "1"
                      } },
                    { "2", new ColumnFamily {
                          Name = "2"
                      } },
                    { "3", new ColumnFamily {
                          Name = "3"
                      } }
                }
            }, keyspace);
        }