Esempio n. 1
0
        internal async Task <bool> RebuildTokenMapAsync(bool retry)
        {
            var currentCounter = Interlocked.Read(ref _counterRebuild);

            Metadata.Logger.Info("Retrieving keyspaces metadata");
            // running this statement synchronously inside the exclusive scheduler deadlocks
            var ksList = await _schemaParser.GetKeyspaces(retry).ConfigureAwait(false);

            var task = _tokenMapTaskFactory.StartNew(() =>
            {
                if (!RebuildNecessary(currentCounter))
                {
                    return(true);
                }

                Metadata.Logger.Info("Updating keyspaces metadata");
                var ksMap  = ksList.Select(ks => new KeyValuePair <string, KeyspaceMetadata>(ks.Name, ks));
                _keyspaces = new ConcurrentDictionary <string, KeyspaceMetadata>(ksMap);
                Metadata.Logger.Info("Rebuilding token map");
                if (Partitioner == null)
                {
                    throw new DriverInternalError("Partitioner can not be null");
                }

                _tokenMap = TokenMap.Build(Partitioner, Hosts.ToCollection(), _keyspaces.Values);
                return(true);
            });

            return(await task.ConfigureAwait(false));
        }
Esempio n. 2
0
        internal async Task RebuildTokenMapAsync(bool retry, bool fetchKeyspaces)
        {
            IEnumerable <KeyspaceMetadata> ksList = null;

            if (fetchKeyspaces)
            {
                Metadata.Logger.Info("Retrieving keyspaces metadata");
                ksList = await _schemaParser.GetKeyspacesAsync(retry).ConfigureAwait(false);
            }

            ConcurrentDictionary <string, KeyspaceMetadata> keyspaces;

            if (ksList != null)
            {
                Metadata.Logger.Info("Updating keyspaces metadata");
                var ksMap = ksList.Select(ks => new KeyValuePair <string, KeyspaceMetadata>(ks.Name, ks));
                keyspaces = new ConcurrentDictionary <string, KeyspaceMetadata>(ksMap);
            }
            else
            {
                keyspaces = _keyspaces;
            }

            Metadata.Logger.Info("Rebuilding token map");
            if (Partitioner == null)
            {
                throw new DriverInternalError("Partitioner can not be null");
            }

            var tokenMap = TokenMap.Build(Partitioner, Hosts.ToCollection(), keyspaces.Values);

            _keyspaces = keyspaces;
            _tokenMap  = tokenMap;
        }
 internal void RebuildTokenMap()
 {
     if (!Configuration.Policies.LoadBalancingPolicy.RequiresTokenMap)
     {
         Logger.Info("Skip rebuilding token map");
         return;
     }
     Logger.Info("Rebuilding token map");
     if (Partitioner == null)
     {
         throw new DriverInternalError("Partitioner can not be null");
     }
     _tokenMap = TokenMap.Build(Partitioner, Hosts.ToCollection(), _keyspaces.Values);
 }
Esempio n. 4
0
 /// <summary>
 ///  Returns all known hosts of this cluster.
 /// </summary>
 /// <returns>collection of all known hosts of this cluster.</returns>
 public ICollection <Host> AllHosts()
 {
     return(Hosts.ToCollection());
 }