Beispiel #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));
        }
Beispiel #2
0
 /// <summary>
 /// Retrieves the keyspaces, stores the information in the internal state and rebuilds the token map
 /// </summary>
 internal Task <bool> RefreshKeyspaces(bool retry = false)
 {
     Logger.Info("Retrieving keyspaces metadata");
     return(_schemaParser
            .GetKeyspaces(retry)
            .ContinueSync(ksList =>
     {
         var ksMap = new ConcurrentDictionary <string, KeyspaceMetadata>();
         foreach (var ks in ksList)
         {
             ksMap.AddOrUpdate(ks.Name, ks, (k, v) => v);
         }
         _keyspaces = ksMap;
         RebuildTokenMap();
         return true;
     }));
 }