/// <summary> /// Executes a "get" over the connection. Return values are set into Output /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { ColumnOrSuperColumn columnOrSupercolumn = null; ColumnPath columnPath = this.BuildColumnPath(this.ColumnFamily, this.SuperColumnName, this.ColumnName); try { columnOrSupercolumn = cassandraClient.get(this.KeySpace, this.Key, columnPath, this.GetCassandraConsistencyLevel()); } catch (NotFoundException ex) { logger.Warn( logger.StringFormatInvariantCulture("{{ KeySpace: '{0}', Key: '{1}', ColumnFamily: '{2}', SuperColumn: '{3}', Column: '{4}' }} not found.", this.KeySpace, this.Key, this.ColumnFamily, (this.SuperColumnName != null) ? this.SuperColumnName : String.Empty, (this.ColumnName != null) ? this.ColumnName : String.Empty), ex); } if (columnOrSupercolumn != null) { this.buildOut(columnOrSupercolumn); } else { // in case of reuse of the command this.Output = null; } }
/// <summary> /// Executes a "multiget_slice" over the connection. No return values. /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { this.Output = null; ColumnParent columnParent = this.BuildColumnParent(this.SuperColumn); SlicePredicate predicate = this.Predicate.ToThrift(); Dictionary<string, List<ColumnOrSuperColumn>> output = cassandraClient.multiget_slice(this.KeySpace, this.Keys, columnParent, predicate, this.GetCassandraConsistencyLevel()); this.buildOut(output); }
/// <summary> /// Executes a "insert" over the connection. No return values. /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { logger.Debug(logger.StringFormatInvariantCulture("Adding key '{0}' from columnFamily '{1}' from KeySpace '{2}'.", this.Key, this.ColumnFamily, this.KeySpace)); Column column = this.Column.ToThrift(); ColumnPath columnPath = this.BuildColumnPath(this.ColumnFamily, this.SuperColumn, this.Column.ColumnName); cassandraClient.insert(this.KeySpace, this.Key, columnPath, column.Value, column.Timestamp, this.GetCassandraConsistencyLevel()); }
/// <summary> /// Executes a "get_range_slices" over the connection. No return values. /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { this.Output = null; ColumnParent columnParent = this.BuildColumnParent(this.SuperColumn); SlicePredicate predicate = this.Predicate.ToThrift(); // Dictionary<string, List<ColumnOrSuperColumn>> output KeyRange keyRange = this.KeyTokenRange.ToThrift(); List<KeySlice> result = cassandraClient.get_range_slices(this.KeySpace, columnParent, predicate, keyRange, this.GetCassandraConsistencyLevel()); this.buildOut(result); }
/// <summary> /// Executes a "remove" over the connection. No return values /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { ColumnPath columnPath; if (this.Column != null) { logger.Debug(logger.StringFormatInvariantCulture("Removing column '{0}' for key '{1}' from columnFamily '{2}' from KeySpace '{3}'.", this.Column.ColumnName, this.Key, this.ColumnFamily, this.KeySpace)); columnPath = this.BuildColumnPath(this.ColumnFamily, this.SuperColumnName, this.Column.ColumnName); cassandraClient.remove(this.KeySpace, this.Key, columnPath, this.Column.Timestamp.Value, this.GetCassandraConsistencyLevel()); } else { logger.Debug(logger.StringFormatInvariantCulture("Removing key '{0}' from columnFamily '{1}' from KeySpace '{2}'.", this.Key, this.ColumnFamily, this.KeySpace)); columnPath = this.BuildColumnPath(this.ColumnFamily, this.SuperColumnName, null); cassandraClient.remove(this.KeySpace, this.Key, columnPath, UnixHelper.UnixTimestamp, this.GetCassandraConsistencyLevel()); } }
public void Start(bool fromScratch = false) { Cassandra.Start(fromScratch); }
/// <summary> /// Executes a "login" over the connection. /// <remarks>In case the login fails, posible login exceptions are AuthenticationException, AuthorizationException</remarks> /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { AuthenticationRequest authReq = this.BuildAuthenticationRequest(); cassandraClient.login(this.KeySpace, authReq); }
/// <summary> /// Executes a "remove" over the connection. No return values /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { Dictionary<string, Dictionary<string, List<Mutation>>> mutation_map = this.translate(this.Mutations); cassandraClient.batch_mutate(this.KeySpace, mutation_map, this.GetCassandraConsistencyLevel()); }
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 + "'"); }
/// <summary> /// Executes a "get_count" over the connection. Return values are set into Output /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { ColumnParent columnParent = this.BuildColumnParent(this.SuperColumnName); this.Count = cassandraClient.get_count(this.KeySpace, this.Key, columnParent, this.GetCassandraConsistencyLevel()); }
public void AddColumn(string key, string cf, string name, int value, Cassandra.Client client) { client.insert(ToByte(key), GetParent(cf), NewColumn(name, value), ConsistencyLevel.ONE); }
public static List<KeySlice> GetAllFromCF(string cf, int count, Cassandra.Client client) { return client.get_range_slices(GetParent(cf), GetPredicate(count), GetKeyRange(count), ConsistencyLevel.ONE); }
public CassandraClient(Cassandra.Client cassandraClient, CassandraEndpoint endpoint) { this.InnerClient = cassandraClient; this.Endpoint = endpoint; }
/// <summary> /// Executes a "describe_keyspaces" over the connection, set the KeySpaces property with the returned value. /// </summary> /// <param name="cassandraClient">opened Thrift client</param> public void Execute(Cassandra.Client cassandraClient) { THashSet<string> keySpaces = cassandraClient.describe_keyspaces(); this.KeySpaces = new HashSet<string>(keySpaces); }