internal async Task <KeyspaceMetadata> UpdateTokenMapForKeyspace(string name) { var currentCounter = Interlocked.Read(ref _counterRebuild); var currentKeyspaceCounter = _keyspacesUpdateCounters.GetOrAdd(name, s => 0); // running this statement synchronously inside the exclusive scheduler deadlocks var keyspaceMetadata = await _schemaParser.GetKeyspace(name).ConfigureAwait(false); var task = _tokenMapTaskFactory.StartNew( () => { if (AnotherRebuildCompleted(currentCounter)) { return(true); } if (!UpdateKeyspaceNecessary(name, currentKeyspaceCounter)) { return(true); } if (_tokenMap == null) { return(false); } Metadata.Logger.Verbose("Updating keyspace metadata: " + name); if (keyspaceMetadata == null) { return((bool?)null); } _keyspaces.AddOrUpdate(keyspaceMetadata.Name, keyspaceMetadata, (k, v) => keyspaceMetadata); Metadata.Logger.Info("Rebuilding token map for keyspace {0}", keyspaceMetadata.Name); if (Partitioner == null) { throw new DriverInternalError("Partitioner can not be null"); } _tokenMap.UpdateKeyspace(keyspaceMetadata); return(true); }); var existsTokenMap = await task.ConfigureAwait(false); if (existsTokenMap.HasValue && !existsTokenMap.Value) { await RefreshKeyspaces().ConfigureAwait(false); } return(keyspaceMetadata); }
internal Task <KeyspaceMetadata> RefreshSingleKeyspace(bool added, string name) { Logger.Verbose("Updating keyspace metadata: " + name); return(_schemaParser.GetKeyspace(name).ContinueSync(ks => { if (ks == null) { return null; } _keyspaces.AddOrUpdate(name, ks, (k, v) => ks); RebuildTokenMap(); var eventKind = added ? SchemaChangedEventArgs.Kind.Created : SchemaChangedEventArgs.Kind.Updated; FireSchemaChangedEvent(eventKind, name, null, this); return ks; })); }