Esempio n. 1
0
        /// <summary>
        ///  Returns metadata of specified keyspace.
        /// </summary>
        /// <param name="keyspace"> the name of the keyspace for which metadata should be
        ///  returned. </param>
        /// <returns>the metadata of the requested keyspace or <c>null</c> if
        ///  <c>* keyspace</c> is not a known keyspace.</returns>
        public KeyspaceMetadata GetKeyspace(string keyspace)
        {
            if (Configuration.MetadataSyncOptions.MetadataSyncEnabled)
            {
                //Use local cache
                _keyspaces.TryGetValue(keyspace, out var ksInfo);
                return(ksInfo);
            }

            return(TaskHelper.WaitToComplete(SchemaParser.GetKeyspaceAsync(keyspace), _queryAbortTimeout));
        }
Esempio n. 2
0
        internal async Task <KeyspaceMetadata> UpdateTokenMapForKeyspace(string name)
        {
            var keyspaceMetadata = await _schemaParser.GetKeyspaceAsync(name).ConfigureAwait(false);

            var dropped = false;
            var updated = false;

            if (_tokenMap == null)
            {
                await RebuildTokenMapAsync(false, false).ConfigureAwait(false);
            }

            if (keyspaceMetadata == null)
            {
                Metadata.Logger.Verbose("Removing keyspace metadata: " + name);
                dropped = _keyspaces.TryRemove(name, out _);
                _tokenMap?.RemoveKeyspace(name);
            }
            else
            {
                Metadata.Logger.Verbose("Updating keyspace metadata: " + name);
                _keyspaces.AddOrUpdate(keyspaceMetadata.Name, keyspaceMetadata, (k, v) =>
                {
                    updated = true;
                    return(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);
            }

            if (Configuration.MetadataSyncOptions.MetadataSyncEnabled)
            {
                if (dropped)
                {
                    FireSchemaChangedEvent(SchemaChangedEventArgs.Kind.Dropped, name, null, this);
                }
                else if (updated)
                {
                    FireSchemaChangedEvent(SchemaChangedEventArgs.Kind.Updated, name, null, this);
                }
                else
                {
                    FireSchemaChangedEvent(SchemaChangedEventArgs.Kind.Created, name, null, this);
                }
            }

            return(keyspaceMetadata);
        }