private RowSet ProcessRowset(IOutput outp, string originCqlQuery) { using (outp) { if (outp is OutputError) { DriverException ex = (outp as OutputError).CreateException(); _logger.Error(ex); throw ex; } else if (outp is OutputVoid) { return(null); } else if (outp is OutputSchemaChange) { return(null); } else if (outp is OutputRows) { var queryHandler = new QueryRequestHandler(); return(queryHandler.ProcessResponse(outp, _session)); } else { var ex = new DriverInternalError("Unexpected output kind"); _logger.Error(ex); throw ex; } } }
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, CqlQueryTools.SelectSchemaPeers, false, QueryProtocolOptions.Default, _cluster.Configuration.QueryOptions.GetConsistencyLevel())) { if (outp is OutputRows) { var requestHandler = new QueryRequestHandler(); var rowset = requestHandler.ProcessResponse(outp, null); foreach (var row in rowset.GetRows()) { if (row.IsNull("rpc_address") || row.IsNull("schema_version")) { continue; } var rpc = row.GetValue <IPAddress>("rpc_address"); if (rpc.Equals(BindAllAddress)) { if (!row.IsNull("peer")) { rpc = row.GetValue <IPAddress>("peer"); } } Host peer = _cluster.Metadata.GetHost(rpc); if (peer != null && peer.IsConsiderablyUp) { versions.Add(row.GetValue <Guid>("schema_version")); } } } } } { using (var outp = connection.Query(streamId2, CqlQueryTools.SelectSchemaLocal, false, QueryProtocolOptions.Default, _cluster.Configuration.QueryOptions.GetConsistencyLevel())) { if (outp is OutputRows) { var requestHandler = new QueryRequestHandler(); var rowset = requestHandler.ProcessResponse(outp, null); 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); }