예제 #1
0
 internal OutputRows(FrameReader reader, Guid? traceId)
 {
     _metadata = new RowSetMetadata(reader);
     _rowLength = reader.ReadInt32();
     TraceId = traceId;
     RowSet = new RowSet();
     ProcessRows(RowSet, reader);
 }
예제 #2
0
 internal CqlReader(RowSet rows)
 {
     this.popul = rows;
     for (int idx = 0; idx < popul.Columns.Length; idx++)
         colidx.Add(popul.Columns[idx].Name, idx);
     enumRows = popul.GetRows();
     enumerRows = enumRows.GetEnumerator();
 }
예제 #3
0
 internal OutputRows(byte protocolVersion, FrameReader reader, Guid? traceId)
 {
     _protocolVersion = protocolVersion;
     _metadata = new RowSetMetadata(reader);
     _rowLength = reader.ReadInt32();
     TraceId = traceId;
     RowSet = new RowSet();
     ProcessRows(RowSet, reader);
 }
예제 #4
0
 internal OutputRows(byte protocolVersion, BEBinaryReader reader, bool buffered, Guid? traceId)
 {
     _protocolVersion = protocolVersion;
     _metadata = new RowSetMetadata(reader);
     RowLength = reader.ReadInt32();
     _traceId = traceId;
     RowSet = new RowSet();
     ProcessRows(RowSet, reader);
 }
        //public bool ChangeProductName(Product product)
        //{
        //    PreparedStatement ps = session.Prepare("UPDATE product SET name=? WHERE id=?");
        //    BoundStatement statement = ps.Bind(name, productId.ToString());
        //    RowSet rowSet = session.Execute(statement);
        //    return true;
        //}
        //public bool ChangeProductDescription(Guid productId, string description)
        //{
        //    PreparedStatement ps = session.Prepare("UPDATE product SET description=? WHERE id=?");
        //    BoundStatement statement = ps.Bind(description, productId.ToString());
        //    RowSet rowSet = session.Execute(statement);
        //    return true;
        //}
        //public bool ChangeProductPrice(Guid productId, double price)
        //{
        //    PreparedStatement ps = session.Prepare("UPDATE product SET price=? WHERE id=?");
        //    BoundStatement statement = ps.Bind(price, productId.ToString());
        //    RowSet rowSet = session.Execute(statement);
        //    return true;
        //}
        public bool DeleteProduct(Guid productId)
        {
            dynamic ps        = session.Prepare($"DELETE FROM {Product.TABLE_NAME} WHERE {Product.COL_ID}=?;");
            var     statement = ps.Bind(productId.ToString());

            Cassandra.RowSet x = session.Execute(statement);
            //Console.WriteLine(x.Info.QueriedHost)
            return(true);
        }
예제 #6
0
 /// <summary>
 /// Process rows and sets the paging event handler
 /// </summary>
 internal void ProcessRows(RowSet rs, BEBinaryReader reader)
 {
     if (_metadata != null)
     {
         rs.Columns = _metadata.Columns;
         rs.PagingState = _metadata.PagingState;
     }
     for (var i = 0; i < this.RowLength; i++)
     {
         rs.AddRow(ProcessRowItem(reader));
     }
 }
 public void PrintResults(RowSet results)
 {
     Console.WriteLine(String.Format("{0, -30}\t{1, -20}\t{2, -20}\t{3, -30}",
         "title", "album", "artist", "tags"));
     Console.WriteLine("-------------------------------+-----------------------+--------------------+-------------------------------");
     foreach (Row row in results.GetRows())
     {
         Console.WriteLine(String.Format("{0, -30}\t{1, -20}\t{2, -20}\t{3}",
             row.GetValue<String>("title"), row.GetValue<String>("album"),
             row.GetValue<String>("artist"), Prettify( row.GetValue<List<String>>("tags")
             ) ));
     }
 }
예제 #8
0
 private static void DisplayKeyspace(RowSet result)
 {
     try
     {
         foreach (var resKeyspace in result.GetRows())
         {
             Console.WriteLine("durable_writes={0} keyspace_name={1} strategy_Class={2} strategy_options={3}",
                               resKeyspace.GetValue<bool>("durable_writes"),
                               resKeyspace.GetValue<string>("keyspace_name"),
                               resKeyspace.GetValue<string>("strategy_class"),
                               resKeyspace.GetValue<string>("strategy_options"));
         }
         Console.WriteLine();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Command failed {0}", ex.Message);
     }
 }
예제 #9
0
        /// <summary>
        /// Checks if the exception is either a Cassandra response error or a socket exception to retry or failover if necessary.
        /// </summary>
        private void HandleException(Exception ex)
        {
            _logger.Info("RequestHandler received exception {0}", ex.ToString());
            if (ex is PreparedQueryNotFoundException && (_statement is BoundStatement || _statement is BatchStatement))
            {
                PrepareAndRetry(((PreparedQueryNotFoundException)ex).UnknownId);
                return;
            }
            if (ex is SocketException)
            {
                _logger.Verbose("Socket error " + ((SocketException)ex).SocketErrorCode);
                SetHostDown(Host, _connection, ex);
            }
            var decision = GetRetryDecision(ex);

            switch (decision.DecisionType)
            {
            case RetryDecision.RetryDecisionType.Rethrow:
                _tcs.TrySetException(ex);
                break;

            case RetryDecision.RetryDecisionType.Ignore:
                //The error was ignored by the RetryPolicy
                //Try to give a decent response
                if (typeof(T).IsAssignableFrom(typeof(RowSet)))
                {
                    var rs = new RowSet();
                    _tcs.TrySetResult((T)(object)FillRowSet(rs, null));
                }
                else
                {
                    _tcs.TrySetResult(default(T));
                }
                break;

            case RetryDecision.RetryDecisionType.Retry:
                //Retry the Request using the new consistency level
                Retry(decision.RetryConsistencyLevel);
                break;
            }
        }
예제 #10
0
 /// <summary>
 /// Fills the common properties of the RowSet
 /// </summary>
 private RowSet FillRowSet(RowSet rs)
 {
     rs.Info.SetTriedHosts(_triedHosts.Keys.ToList());
     if (_request is ICqlRequest)
     {
         rs.Info.SetAchievedConsistency(((ICqlRequest)_request).Consistency);
     }
     if (rs.PagingState != null && _request is IQueryRequest && typeof(T) == typeof(RowSet))
     {
         rs.FetchNextPage = (pagingState) =>
         {
             if (_session.IsDisposed)
             {
                 _logger.Warning("Trying to page results using a Session already disposed.");
                 return(new RowSet());
             }
             ((IQueryRequest)_request).PagingState = pagingState;
             var task = new RequestHandler <RowSet>(_session, _request, _statement).Send();
             TaskHelper.WaitToComplete(task, _session.Configuration.ClientOptions.QueryAbortTimeout);
             return((RowSet)(object)task.Result);
         };
     }
     return(rs);
 }
예제 #11
0
 public void WaitForSchemaAgreement(RowSet rs)
 {
     _metadata.WaitForSchemaAgreement(rs.Info.QueriedHost);
 }
예제 #12
0
 public void WaitForSchemaAgreement(RowSet rs)
 {
 }
예제 #13
0
        private void RefreshNodeListAndTokenMap()
        {
            _logger.Info("Refreshing NodeList and TokenMap..");
            // Make sure we're up to date on nodes and tokens
            var tokenMap = new Dictionary<IPAddress, DictSet<string>>();
            string partitioner = null;

            var foundHosts = new List<IPAddress>();
            var dcs = new List<string>();
            var racks = new List<string>();
            var allTokens = new List<DictSet<string>>();
            IPAddress queriedHost;

            using (var rowset = _session.Query(SelectPeers, ConsistencyLevel.Quorum))
            {
                queriedHost = rowset.Info.QueriedHost;
                foreach (var row in rowset.GetRows())
                {
                    IPAddress hstip = null;
                    if(!row.IsNull("rpc_address"))
                         hstip = row.GetValue<IPEndPoint>("rpc_address").Address;
                    if (hstip == null)
                    {
                        if (!row.IsNull("peer"))
                            hstip = row.GetValue<IPEndPoint>("peer").Address;
                        _logger.Error("No rpc_address found for host in peers system table. ");
                    }
                    else if (hstip.Equals(bindAllAddress))
                    {
                        if (!row.IsNull("peer"))
                            hstip = row.GetValue<IPEndPoint>("peer").Address;
                    }

                    if (hstip != null)
                    {
                        foundHosts.Add(hstip);
                        dcs.Add(row.GetValue<string>("data_center"));
                        racks.Add(row.GetValue<string>("rack"));
                        var col = row.GetValue<IEnumerable<string>>("tokens");
                        if (col == null)
                            allTokens.Add(new DictSet<string>());
                        else
                            allTokens.Add(new DictSet<string>(col));
                    }
                }
            }

            var localhost = _cluster.Metadata.GetHost(queriedHost);
            var iterLiof = new List<Host>() { localhost }.GetEnumerator();
            iterLiof.MoveNext();
            List<IPAddress> tr = new List<IPAddress>();
            Dictionary<IPAddress, List<Exception>> exx = new Dictionary<IPAddress, List<Exception>>();
            var cn = _session.Connect(null, iterLiof, tr, exx);

            using (var outp = cn.Query(SelectLocal, ConsistencyLevel.Default,false))
            {
                if (outp is OutputRows)
                {
                    var rowset = new RowSet((outp as OutputRows), null, false);
                    // Update cluster name, DC and rack for the one node we are connected to
                    foreach (var localRow in rowset.GetRows())
                    {
                        var clusterName = localRow.GetValue<string>("cluster_name");
                        if (clusterName != null)
                            _cluster.Metadata.ClusterName = clusterName;

                        // In theory host can't be null. However there is no point in risking a NPE in case we
                        // have a race between a node removal and this.
                        if (localhost != null)
                        {
                            localhost.SetLocationInfo(localRow.GetValue<string>("data_center"), localRow.GetValue<string>("rack"));

                            partitioner = localRow.GetValue<string>("partitioner");
                            var tokens = localRow.GetValue<IList<string>>("tokens");
                            if (partitioner != null && tokens.Count > 0)
                            {
                                if (!tokenMap.ContainsKey(localhost.Address))
                                    tokenMap.Add(localhost.Address, new DictSet<string>());
                                tokenMap[localhost.Address].AddRange(tokens);
                            }
                        }

                        break; //fetch only one row
                    }
                }
            }

            for (int i = 0; i < foundHosts.Count; i++)
            {
                var host = _cluster.Metadata.GetHost(foundHosts[i]);
                if (host == null)
                {
                    // We don't know that node, add it.
                    host = _cluster.Metadata.AddHost(foundHosts[i]);
                }
                host.SetLocationInfo(dcs[i], racks[i]);

                if (partitioner != null && !allTokens[i].IsEmpty)
                    tokenMap.Add(host.Address, allTokens[i]);
            }

            // Removes all those that seems to have been removed (since we lost the control connection)
            var foundHostsSet = new DictSet<IPAddress>(foundHosts);
            foreach (var host in _cluster.Metadata.AllReplicas())
                if (!host.Equals(queriedHost) && !foundHostsSet.Contains(host))
                    _cluster.Metadata.RemoveHost(host);

            if (partitioner != null)
                _cluster.Metadata.RebuildTokenMap(partitioner, tokenMap);

            _logger.Info("NodeList and TokenMap have been successfully refreshed!");
        }
예제 #14
0
        internal bool WaitForSchemaAgreement(IPAddress forHost = null)
        {
            var start = DateTimeOffset.Now;
            long elapsed = 0;
            while (elapsed < MaxSchemaAgreementWaitMs)
            {
                var versions = new DictSet<Guid>();

                IPAddress queriedHost;

                if (forHost == null)
                {
                    using (var rowset = _session.Query(SelectSchemaPeers, ConsistencyLevel.Default))
                    {
                        queriedHost = rowset.Info.QueriedHost;
                        foreach (var row in rowset.GetRows())
                        {
                            if (row.IsNull("rpc_address") || row.IsNull("schema_version"))
                                continue;

                            var rpc = row.GetValue<IPEndPoint>("rpc_address").Address;
                            if (rpc.Equals(bindAllAddress))
                                if (!row.IsNull("peer"))
                                    rpc = row.GetValue<IPEndPoint>("peer").Address;

                            Host peer = _cluster.Metadata.GetHost(rpc);
                            if (peer != null && peer.IsConsiderablyUp)
                                versions.Add(row.GetValue<Guid>("schema_version"));
                        }
                    }
                }
                else
                {
                    queriedHost = forHost;
                    var localhost = _cluster.Metadata.GetHost(queriedHost);
                    var iterLiof = new List<Host>() { localhost }.GetEnumerator();
                    iterLiof.MoveNext();
                    List<IPAddress> tr = new List<IPAddress>();
                    Dictionary<IPAddress, List<Exception>> exx = new Dictionary<IPAddress, List<Exception>>();
                    var cn = _session.Connect(null, iterLiof, tr, exx);

                    using (var outp = cn.Query(SelectSchemaPeers, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            foreach (var row in rowset.GetRows())
                            {
                                if (row.IsNull("rpc_address") || row.IsNull("schema_version"))
                                    continue;

                                var rpc = row.GetValue<IPEndPoint>("rpc_address").Address;
                                if (rpc.Equals(bindAllAddress))
                                {
                                    if (!row.IsNull("peer"))
                                        rpc = row.GetValue<IPEndPoint>("peer").Address;
                                }

                                Host peer = _cluster.Metadata.GetHost(rpc);
                                if (peer != null && peer.IsConsiderablyUp)
                                    versions.Add(row.GetValue<Guid>("schema_version"));
                            }
                        }
                    }
                }

                {
                    var localhost = _cluster.Metadata.GetHost(queriedHost);
                    var iterLiof = new List<Host>() { localhost }.GetEnumerator();
                    iterLiof.MoveNext();
                    List<IPAddress> tr = new List<IPAddress>();
                    Dictionary<IPAddress, List<Exception>> exx = new Dictionary<IPAddress, List<Exception>>();
                    var cn = _session.Connect(null, iterLiof, tr, exx);

                    using (var outp = cn.Query(SelectSchemaLocal, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            // Update cluster name, DC and rack for the one node we are connected to
                            foreach (var localRow in rowset.GetRows())
                                if (!localRow.IsNull("schema_version"))
                                {
                                    versions.Add(localRow.GetValue<Guid>("schema_version"));
                                    break;
                                }
                        }
                    }
                }

                if (versions.Count <= 1)
                    return true;

                // let's not flood the node too much
                Thread.Sleep(200);
                elapsed = (long)(DateTimeOffset.Now - start).TotalMilliseconds;
            }

            return false;
        }
예제 #15
0
 public void WaitForSchemaAgreement(RowSet rs)
 {
     #pragma warning disable 618
     _coreSession.WaitForSchemaAgreement(rs);
     #pragma warning restore 618
 }
예제 #16
0
 public RowStream(RowSet rowSet, string path = null, int bufferSize = 8192)
     : base(path ?? Path.GetTempFileName(), FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize, FileOptions.DeleteOnClose)
 {
     _rowSetEnumerator = rowSet.GetEnumerator();
     ReadFully();
 }
예제 #17
0
        internal bool WaitForSchemaAgreement(IPAddress forHost = null)
        {
            var  start   = DateTimeOffset.Now;
            long elapsed = 0;

            while (elapsed < MaxSchemaAgreementWaitMs)
            {
                var versions = new DictSet <Guid>();


                IPAddress queriedHost;

                if (forHost == null)
                {
                    using (var rowset = _session.Query(SelectSchemaPeers, ConsistencyLevel.Default))
                    {
                        queriedHost = rowset.Info.QueriedHost;
                        foreach (var row in rowset.GetRows())
                        {
                            if (row.IsNull("rpc_address") || row.IsNull("schema_version"))
                            {
                                continue;
                            }

                            var rpc = row.GetValue <IPEndPoint>("rpc_address").Address;
                            if (rpc.Equals(bindAllAddress))
                            {
                                if (!row.IsNull("peer"))
                                {
                                    rpc = row.GetValue <IPEndPoint>("peer").Address;
                                }
                            }

                            Host peer = _cluster.Metadata.GetHost(rpc);
                            if (peer != null && peer.IsConsiderablyUp)
                            {
                                versions.Add(row.GetValue <Guid>("schema_version"));
                            }
                        }
                    }
                }
                else
                {
                    queriedHost = forHost;
                    var localhost = _cluster.Metadata.GetHost(queriedHost);
                    var iterLiof  = new List <Host>()
                    {
                        localhost
                    }.GetEnumerator();
                    iterLiof.MoveNext();
                    List <IPAddress> tr = new List <IPAddress>();
                    Dictionary <IPAddress, List <Exception> > exx = new Dictionary <IPAddress, List <Exception> >();
                    int streamId;

                    var cn = _session.Connect(null, iterLiof, tr, exx, out streamId);

                    using (var outp = cn.Query(streamId, SelectSchemaPeers, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            foreach (var row in rowset.GetRows())
                            {
                                if (row.IsNull("rpc_address") || row.IsNull("schema_version"))
                                {
                                    continue;
                                }

                                var rpc = row.GetValue <IPEndPoint>("rpc_address").Address;
                                if (rpc.Equals(bindAllAddress))
                                {
                                    if (!row.IsNull("peer"))
                                    {
                                        rpc = row.GetValue <IPEndPoint>("peer").Address;
                                    }
                                }

                                Host peer = _cluster.Metadata.GetHost(rpc);
                                if (peer != null && peer.IsConsiderablyUp)
                                {
                                    versions.Add(row.GetValue <Guid>("schema_version"));
                                }
                            }
                        }
                    }
                }

                {
                    var localhost = _cluster.Metadata.GetHost(queriedHost);
                    var iterLiof  = new List <Host>()
                    {
                        localhost
                    }.GetEnumerator();
                    iterLiof.MoveNext();
                    List <IPAddress> tr = new List <IPAddress>();
                    Dictionary <IPAddress, List <Exception> > exx = new Dictionary <IPAddress, List <Exception> >();
                    int streamId;
                    var cn = _session.Connect(null, iterLiof, tr, exx, out streamId);

                    using (var outp = cn.Query(streamId, SelectSchemaLocal, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            // Update cluster name, DC and rack for the one node we are connected to
                            foreach (var localRow in rowset.GetRows())
                            {
                                if (!localRow.IsNull("schema_version"))
                                {
                                    versions.Add(localRow.GetValue <Guid>("schema_version"));
                                    break;
                                }
                            }
                        }
                    }
                }


                if (versions.Count <= 1)
                {
                    return(true);
                }

                // let's not flood the node too much
                Thread.Sleep(200);
                elapsed = (long)(DateTimeOffset.Now - start).TotalMilliseconds;
            }

            return(false);
        }
예제 #18
0
        private void RefreshNodeListAndTokenMap()
        {
            _logger.Info("Refreshing NodeList and TokenMap..");
            // Make sure we're up to date on nodes and tokens
            var    tokenMap    = new Dictionary <IPAddress, DictSet <string> >();
            string partitioner = null;

            var       foundHosts = new List <IPAddress>();
            var       dcs        = new List <string>();
            var       racks      = new List <string>();
            var       allTokens  = new List <DictSet <string> >();
            IPAddress queriedHost;

            using (var rowset = _session.Query(SelectPeers, ConsistencyLevel.Quorum))
            {
                queriedHost = rowset.Info.QueriedHost;
                foreach (var row in rowset.GetRows())
                {
                    IPAddress hstip = null;
                    if (!row.IsNull("rpc_address"))
                    {
                        hstip = row.GetValue <IPEndPoint>("rpc_address").Address;
                    }
                    if (hstip == null)
                    {
                        if (!row.IsNull("peer"))
                        {
                            hstip = row.GetValue <IPEndPoint>("peer").Address;
                        }
                        _logger.Error("No rpc_address found for host in peers system table. ");
                    }
                    else if (hstip.Equals(bindAllAddress))
                    {
                        if (!row.IsNull("peer"))
                        {
                            hstip = row.GetValue <IPEndPoint>("peer").Address;
                        }
                    }

                    if (hstip != null)
                    {
                        foundHosts.Add(hstip);
                        dcs.Add(row.GetValue <string>("data_center"));
                        racks.Add(row.GetValue <string>("rack"));
                        var col = row.GetValue <IEnumerable <string> >("tokens");
                        if (col == null)
                        {
                            allTokens.Add(new DictSet <string>());
                        }
                        else
                        {
                            allTokens.Add(new DictSet <string>(col));
                        }
                    }
                }
            }

            var localhost = _cluster.Metadata.GetHost(queriedHost);
            var iterLiof  = new List <Host>()
            {
                localhost
            }.GetEnumerator();

            iterLiof.MoveNext();
            List <IPAddress> tr = new List <IPAddress>();
            Dictionary <IPAddress, List <Exception> > exx = new Dictionary <IPAddress, List <Exception> >();
            int streamId;
            var cn = _session.Connect(null, iterLiof, tr, exx, out streamId);

            using (var outp = cn.Query(streamId, SelectLocal, ConsistencyLevel.Default, false))
            {
                if (outp is OutputRows)
                {
                    var rowset = new RowSet((outp as OutputRows), null, false);
                    // Update cluster name, DC and rack for the one node we are connected to
                    foreach (var localRow in rowset.GetRows())
                    {
                        var clusterName = localRow.GetValue <string>("cluster_name");
                        if (clusterName != null)
                        {
                            _cluster.Metadata.ClusterName = clusterName;
                        }



                        // In theory host can't be null. However there is no point in risking a NPE in case we
                        // have a race between a node removal and this.
                        if (localhost != null)
                        {
                            localhost.SetLocationInfo(localRow.GetValue <string>("data_center"), localRow.GetValue <string>("rack"));

                            partitioner = localRow.GetValue <string>("partitioner");
                            var tokens = localRow.GetValue <IList <string> >("tokens");
                            if (partitioner != null && tokens.Count > 0)
                            {
                                if (!tokenMap.ContainsKey(localhost.Address))
                                {
                                    tokenMap.Add(localhost.Address, new DictSet <string>());
                                }
                                tokenMap[localhost.Address].AddRange(tokens);
                            }
                        }

                        break; //fetch only one row
                    }
                }
            }

            for (int i = 0; i < foundHosts.Count; i++)
            {
                var host = _cluster.Metadata.GetHost(foundHosts[i]);
                if (host == null)
                {
                    // We don't know that node, add it.
                    host = _cluster.Metadata.AddHost(foundHosts[i]);
                }
                host.SetLocationInfo(dcs[i], racks[i]);

                if (partitioner != null && !allTokens[i].IsEmpty)
                {
                    tokenMap.Add(host.Address, allTokens[i]);
                }
            }

            // Removes all those that seems to have been removed (since we lost the control connection)
            var foundHostsSet = new DictSet <IPAddress>(foundHosts);

            foreach (var host in _cluster.Metadata.AllReplicas())
            {
                if (!host.Equals(queriedHost) && !foundHostsSet.Contains(host))
                {
                    _cluster.Metadata.RemoveHost(host);
                }
            }

            if (partitioner != null)
            {
                _cluster.Metadata.RebuildTokenMap(partitioner, tokenMap);
            }

            _logger.Info("NodeList and TokenMap have been successfully refreshed!");
        }
예제 #19
0
 public void WaitForSchemaAgreement(RowSet rs)
 {
     WaitForSchemaAgreement(rs.Info.QueriedHost);
 }
예제 #20
0
 public override void Complete(Session owner, object value, Exception exc = null)
 {
     try
     {
         var ar = LongActionAc as AsyncResult<RowSet>;
         if (exc != null)
             ar.Complete(exc);
         else
         {
             RowSet rowset = value as RowSet;
             if(rowset==null)
                 rowset = new RowSet(null,owner,false);
             rowset.Info.SetTriedHosts(TriedHosts);
             rowset.Info.SetAchievedConsistency(Consistency);
             ar.SetResult(rowset);
             ar.Complete();
         }
     }
     finally
     {
         var ts = StartedAt.ElapsedTicks;
         CassandraCounters.IncrementCqlQueryCount();
         CassandraCounters.IncrementCqlQueryBeats((ts * 1000000000));
         CassandraCounters.UpdateQueryTimeRollingAvrg((ts * 1000000000) / Stopwatch.Frequency);
         CassandraCounters.IncrementCqlQueryBeatsBase();
     }
 }
예제 #21
0
 public void WaitForSchemaAgreement(RowSet rs)
 {
     
 }
예제 #22
0
        public bool WaitForSchemaAgreement(IPAddress forHost)
        {
            var start = DateTimeOffset.Now;
            long elapsed = 0;
            while (elapsed < MaxSchemaAgreementWaitMs)
            {
                var versions = new HashSet<Guid>();

                int streamId1;
                int streamId2;
                CassandraConnection connection;
                {
                    var localhost = _cluster.Metadata.GetHost(forHost);
                    var iterLiof = new List<Host>() { localhost }.GetEnumerator();
                    iterLiof.MoveNext();
                    List<IPAddress> tr = new List<IPAddress>();
                    Dictionary<IPAddress, List<Exception>> exx = new Dictionary<IPAddress, List<Exception>>();

                    connection = Connect(iterLiof, tr, exx, out streamId1);
                    while (true)
                    {
                        try
                        {
                            streamId2 = connection.AllocateStreamId();
                            break;
                        }
                        catch (CassandraConnection.StreamAllocationException)
                        {
                            Thread.Sleep(100);
                        }
                    }
                }
                {

                    using (var outp = connection.Query(streamId1, SelectSchemaPeers, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            foreach (var row in rowset.GetRows())
                            {
                                if (row.IsNull("rpc_address") || row.IsNull("schema_version"))
                                    continue;

                                var rpc = row.GetValue<IPEndPoint>("rpc_address").Address;
                                if (rpc.Equals(bindAllAddress))
                                {
                                    if (!row.IsNull("peer"))
                                        rpc = row.GetValue<IPEndPoint>("peer").Address;
                                }

                                Host peer = _cluster.Metadata.GetHost(rpc);
                                if (peer != null && peer.IsConsiderablyUp)
                                    versions.Add(row.GetValue<Guid>("schema_version"));
                            }
                        }
                    }
                }

                {
                    using (var outp = connection.Query(streamId2, SelectSchemaLocal, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            // Update cluster name, DC and rack for the one node we are connected to
                            foreach (var localRow in rowset.GetRows())
                                if (!localRow.IsNull("schema_version"))
                                {
                                    versions.Add(localRow.GetValue<Guid>("schema_version"));
                                    break;
                                }
                        }
                    }
                }

                if (versions.Count <= 1)
                    return true;

                // let's not flood the node too much
                Thread.Sleep(200);
                elapsed = (long)(DateTimeOffset.Now - start).TotalMilliseconds;
            }

            return false;
        }