Esempio n. 1
0
File: main.cs Progetto: blucz/tood
        private static void _InitCassandra()
        {
            _conn = new Cassandra.Connection();
            Console.WriteLine("[cassandra] connected to cassandra version " + _conn.DescribeVersion());

            Cassandra.KeySpaceDefinition ksdef = new Cassandra.KeySpaceDefinition()
            {
                Name           = "tood",
                ColumnFamilies =
                {
                    new Cassandra.ColumnFamilyDefinition()
                    {
                        Keyspace = "tood",
                        Name     = "users",
                    }
                },
                ReplicationFactor   = 1,
                ReplicationStrategy = Cassandra.ReplicationStrategy.SimpleStrategy,
            };

            _InitializeKeySpace(_conn, ksdef);
        }
Esempio n. 2
0
File: main.cs Progetto: blucz/tood
        private static void _InitCassandra()
        {
            _conn = new Cassandra.Connection();
            Console.WriteLine("[cassandra] connected to cassandra version " + _conn.DescribeVersion());

            Cassandra.KeySpaceDefinition ksdef = new Cassandra.KeySpaceDefinition() {
                Name = "tood",
                ColumnFamilies = {
                    new Cassandra.ColumnFamilyDefinition() {
                        Keyspace = "tood",
                        Name = "users",
                    }
                },
                ReplicationFactor = 1,
                ReplicationStrategy = Cassandra.ReplicationStrategy.SimpleStrategy,
            };

            _InitializeKeySpace(_conn, ksdef);
        }
Esempio n. 3
0
File: main.cs Progetto: blucz/tood
        private static void _InitializeKeySpace(Cassandra.Connection conn, Cassandra.KeySpaceDefinition current)
        {
            Cassandra.KeySpaceDefinition existing;
            try {
                existing = conn.DescribeKeySpace(current.Name);
            } catch (Cassandra.NotFoundException) {
                _conn.SystemAddKeyspace(current);
                _conn.SetKeyspace(current.Name);
                Console.WriteLine("[cassandra] created keyspace '" + current.Name + "'");
                return;
            }

            _conn.SetKeyspace(current.Name);

            Dictionary <string, Cassandra.ColumnFamilyDefinition> cf_toremove = new Dictionary <string, Cassandra.ColumnFamilyDefinition>();
            Dictionary <string, Cassandra.ColumnFamilyDefinition> cf_toadd    = new Dictionary <string, Cassandra.ColumnFamilyDefinition>();
            List <KeyValuePair <Cassandra.ColumnFamilyDefinition, Cassandra.ColumnFamilyDefinition> > cf_toupdate = new List <KeyValuePair <Cassandra.ColumnFamilyDefinition, Cassandra.ColumnFamilyDefinition> >();

            foreach (var cf in existing.ColumnFamilies)
            {
                cf_toremove.Add(cf.Name, cf);
            }

            foreach (var cf in current.ColumnFamilies)
            {
                Cassandra.ColumnFamilyDefinition oldcf;
                if (cf_toremove.TryGetValue(cf.Name, out oldcf))
                {
                    cf_toremove.Remove(cf.Name);
                    cf_toupdate.Add(new KeyValuePair <Cassandra.ColumnFamilyDefinition, Cassandra.ColumnFamilyDefinition>(oldcf, cf));
                }
                else
                {
                    cf_toadd.Add(cf.Name, cf);
                }
            }

            foreach (var cf in cf_toremove.Keys)
            {
                _conn.SystemDropColumnFamily(cf);
                Console.Error.WriteLine("[cassandra] dropped column family '" + cf + "' from keyspace '" + current.Name + "'");
            }

            foreach (var cf in cf_toadd.Values)
            {
                _conn.SystemAddColumnFamily(cf);
                Console.Error.WriteLine("[cassandra] added column family '" + cf.Name + "' to keyspace '" + current.Name + "'");
            }

            foreach (var pair in cf_toupdate)
            {
                pair.Value.Id = pair.Key.Id;
                _conn.SystemUpdateColumnFamily(pair.Value);
                Console.Error.WriteLine("[cassandra] updated column family '" + pair.Value.Name + "' in keyspace '" + current.Name + "'");
            }

            var ksclone = current.Clone();

            ksclone.ColumnFamilies.Clear();
            conn.SystemUpdateKeyspace(ksclone);
            Console.Error.WriteLine("[cassandra] updated keyspace '" + current.Name + "'");
        }