public void UpdateKeyspace(KeyspaceMetadata ks) { var sw = new Stopwatch(); sw.Start(); TokenMap.UpdateKeyspace( ks, _tokenToHostsByKeyspace, _ring, _primaryReplicas, _keyspaceTokensCache, _datacenters, _numberOfHostsWithTokens); sw.Stop(); TokenMap.Logger.Info( "Finished updating TokenMap for the '{0}' keyspace. It took {1:0} milliseconds.", ks.Name, sw.Elapsed.TotalMilliseconds); }
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 static void UpdateKeyspace( KeyspaceMetadata ks, IDictionary <string, IReadOnlyDictionary <IToken, ISet <Host> > > tokenToHostsByKeyspace, IReadOnlyList <IToken> ring, IReadOnlyDictionary <IToken, Host> primaryReplicas, IDictionary <IReplicationStrategy, IReadOnlyDictionary <IToken, ISet <Host> > > keyspaceTokensCache, IReadOnlyDictionary <string, DatacenterInfo> datacenters, int numberOfHostsWithTokens) { IReadOnlyDictionary <IToken, ISet <Host> > replicas; if (ks.Strategy == null) { replicas = primaryReplicas.ToDictionary(kv => kv.Key, kv => (ISet <Host>) new HashSet <Host>(new[] { kv.Value })); } else if (!keyspaceTokensCache.TryGetValue(ks.Strategy, out replicas)) { replicas = ks.Strategy.ComputeTokenToReplicaMap(ring, primaryReplicas, numberOfHostsWithTokens, datacenters); keyspaceTokensCache[ks.Strategy] = replicas; } tokenToHostsByKeyspace[ks.Name] = replicas; }
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); }
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 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; } }
public void RemoveKeyspace(KeyspaceMetadata keyspaceMetadata) { _tokenToHostsByKeyspace.TryRemove(keyspaceMetadata.Name, out _); }
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; }
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 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 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]; } }
/// <summary> /// Removes aggregate metadata forcing refresh the next time the function metadata is retrieved /// </summary> internal void ClearAggregate(string name, string[] signature) { _aggregates.TryRemove(KeyspaceMetadata.GetFunctionKey(name, signature), out _); }
/// <summary> /// Removes function metadata forcing refresh the next time the function metadata is retrieved /// </summary> internal void ClearFunction(string name, string[] signature) { _functions.TryRemove(KeyspaceMetadata.GetFunctionKey(name, signature), out _); }