private ConcurrentDictionary <string, AtomicValue <KeyspaceMetadata> > SetupSchema() { var ks = _keyspaces.Value; if (ks == null) { var newKeyspaces = new ConcurrentDictionary <string, AtomicValue <KeyspaceMetadata> >(); int streamId = _activeConnection.Value.AllocateStreamId(); using (var rows = ProcessRowset(_activeConnection.Value.Query(streamId, SelectKeyspaces, ConsistencyLevel.Default, false))) { foreach (var row in rows.GetRows()) { var strKsName = row.GetValue <string>("keyspace_name"); var strClass = GetStrategyClass(row.GetValue <string>("strategy_class")); var drblWrites = row.GetValue <bool>("durable_writes"); var rplctOptions = Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")); var newMetadata = new KeyspaceMetadata(this, strKsName, drblWrites, strClass, rplctOptions); newKeyspaces.TryAdd(strKsName, new AtomicValue <KeyspaceMetadata>(newMetadata)); } } return(_keyspaces.Value = newKeyspaces); } else { return(ks); } }
private ReadOnlyDictionary <string, KeyspaceMetadata> SetupSchema() { var ks = _keyspaces.Value; if (ks == null) { var newKeyspaces = new ReadOnlyDictionary <string, KeyspaceMetadata>(); using (var rows = _session.Query(SelectKeyspaces)) { foreach (var row in rows.GetRows()) { var strKsName = row.GetValue <string>("keyspace_name"); var strClass = GetStrategyClass(row.GetValue <string>("strategy_class")); var drblWrites = row.GetValue <bool>("durable_writes"); var rplctOptions = Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")); var newMetadata = new KeyspaceMetadata(this, strKsName, drblWrites, strClass, new ReadOnlyDictionary <string, int>(rplctOptions)); newKeyspaces.InternalSetup(strKsName, newMetadata); } } return(_keyspaces.Value = newKeyspaces); } else { return(ks); } }
private KeyspaceMetadata ParseKeyspaceRow(Row row) { return(new KeyspaceMetadata( ControlConnection, row.GetValue <string>("keyspace_name"), row.GetValue <bool>("durable_writes"), row.GetValue <string>("strategy_class"), Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")))); }
private KeyspaceMetadata SetupKeyspace(string keyspace) { var sc = SetupSchema(); AtomicValue <KeyspaceMetadata> ksval; if (!sc.TryGetValue(keyspace, out ksval) || ksval.Value == null || ksval.Value.Tables.Value == null) { WaitForSchemaAgreement(); ResetSchema(); sc = SetupSchema(); KeyspaceMetadata ks = null; { int streamId = _activeConnection.Value.AllocateStreamId(); using (var rows = ProcessRowset(_activeConnection.Value.Query(streamId, string.Format( SelectKeyspaces + " WHERE keyspace_name='{0}';", keyspace), ConsistencyLevel.Default, false))) { foreach (var row in rows.GetRows()) { var strKsName = row.GetValue <string>("keyspace_name"); var strClass = GetStrategyClass(row.GetValue <string>("strategy_class")); var drblWrites = row.GetValue <bool>("durable_writes"); var rplctOptions = Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")); ks = new KeyspaceMetadata(this, strKsName, drblWrites, strClass, rplctOptions); } } if (ks == null) { throw new InvalidOperationException(); } } { int streamId = _activeConnection.Value.AllocateStreamId(); var ktb = new ConcurrentDictionary <string, AtomicValue <TableMetadata> >(); using ( var rows = ProcessRowset(_activeConnection.Value.Query(streamId, string.Format(SelectColumnFamilies + " WHERE keyspace_name='{0}';", keyspace), ConsistencyLevel.Default, false))) { foreach (var row in rows.GetRows()) { ktb.TryAdd(row.GetValue <string>("columnfamily_name"), new AtomicValue <TableMetadata>(null)); } } ks.Tables.Value = ktb; sc.TryAdd(ks.Name, new AtomicValue <KeyspaceMetadata>(ks)); return(ks); } } else { return(ksval.Value); } }
private KeyspaceMetadata SetupKeyspace(string keyspace) { var sc = SetupSchema(); if (!sc.ContainsKey(keyspace) || sc[keyspace].Tables.Value == null) { WaitForSchemaAgreement(); ResetSchema(); sc = SetupSchema(); KeyspaceMetadata ks = null; using ( var rows = _session.Query( string.Format( SelectKeyspaces + " WHERE keyspace_name='{0}';", keyspace))) { foreach (var row in rows.GetRows()) { var strKsName = row.GetValue <string>("keyspace_name"); var strClass = GetStrategyClass(row.GetValue <string>("strategy_class")); var drblWrites = row.GetValue <bool>("durable_writes"); var rplctOptions = Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")); ks = new KeyspaceMetadata(this, strKsName, drblWrites, strClass, new ReadOnlyDictionary <string, int>(rplctOptions)); } } if (ks == null) { throw new InvalidOperationException(); } var ktb = new ReadOnlyDictionary <string, AtomicValue <TableMetadata> >(); using ( var rows = _session.Query(string.Format(SelectColumnFamilies + " WHERE keyspace_name='{0}';", keyspace))) { foreach (var row in rows.GetRows()) { ktb.InternalSetup(row.GetValue <string>("columnfamily_name"), new AtomicValue <TableMetadata>(null)); } } ks.Tables.Value = ktb; sc.InternalSetup(ks.Name, ks); return(ks); } else { return(sc[keyspace]); } }
private KeyspaceMetadata ParseKeyspaceRow(Row row) { if (row == null) { return(null); } return(new KeyspaceMetadata( Parent, row.GetValue <string>("keyspace_name"), row.GetValue <bool>("durable_writes"), row.GetValue <string>("strategy_class"), Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")), false)); }
private KeyspaceMetadata SetupKeyspace(string keyspace) { ConcurrentDictionary <string, AtomicValue <KeyspaceMetadata> > sc = SetupSchema(); AtomicValue <KeyspaceMetadata> ksval; if (!sc.TryGetValue(keyspace, out ksval) || ksval.Value == null || ksval.Value.Tables.Value == null) { WaitForSchemaAgreement(); ResetSchema(); sc = SetupSchema(); KeyspaceMetadata ks = null; { var cqlQuery = String.Format(SelectKeyspaces + " WHERE keyspace_name='{0}';", keyspace); var rows = Query(cqlQuery); foreach (Row row in rows) { var strKsName = row.GetValue <string>("keyspace_name"); string strClass = GetStrategyClass(row.GetValue <string>("strategy_class")); var drblWrites = row.GetValue <bool>("durable_writes"); IDictionary <string, int> rplctOptions = Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")); ks = new KeyspaceMetadata(this, strKsName, drblWrites, strClass, rplctOptions); } if (ks == null) { throw new InvalidOperationException(); } } { var ktb = new ConcurrentDictionary <string, AtomicValue <TableMetadata> >(); var cqlQuery = String.Format(SelectColumnFamilies + " WHERE keyspace_name='{0}';", keyspace); var rows = Query(cqlQuery); foreach (Row row in rows) { ktb.TryAdd(row.GetValue <string>("columnfamily_name"), new AtomicValue <TableMetadata>(null)); } ks.Tables.Value = ktb; sc.TryAdd(ks.Name, new AtomicValue <KeyspaceMetadata>(ks)); return(ks); } } return(ksval.Value); }
private ConcurrentDictionary <string, AtomicValue <KeyspaceMetadata> > SetupSchema() { ConcurrentDictionary <string, AtomicValue <KeyspaceMetadata> > ks = _keyspaces.Value; if (ks == null) { var newKeyspaces = new ConcurrentDictionary <string, AtomicValue <KeyspaceMetadata> >(); var rows = Query(SelectKeyspaces); foreach (Row row in rows) { var strKsName = row.GetValue <string>("keyspace_name"); string strClass = GetStrategyClass(row.GetValue <string>("strategy_class")); var drblWrites = row.GetValue <bool>("durable_writes"); IDictionary <string, int> rplctOptions = Utils.ConvertStringToMapInt(row.GetValue <string>("strategy_options")); var newMetadata = new KeyspaceMetadata(this, strKsName, drblWrites, strClass, rplctOptions); newKeyspaces.TryAdd(strKsName, new AtomicValue <KeyspaceMetadata>(newMetadata)); } return(_keyspaces.Value = newKeyspaces); } return(ks); }