private IStatement AdaptRpcPrimaryResult(RowSet rowSet, TargettedSimpleStatement statement) { var row = rowSet.FirstOrDefault(); if (row == null) { GraphRequestHandler.Logger.Verbose( "Empty response querying graph analytics server, query will not be routed optimally"); return(statement); } var resultField = row.GetValue <IDictionary <string, string> >("result"); if (resultField == null || !resultField.ContainsKey("location") || resultField["location"] == null) { GraphRequestHandler.Logger.Verbose( "Could not extract graph analytics server location from RPC, query will not be routed optimally"); return(statement); } var location = resultField["location"]; var hostName = location.Substring(0, location.LastIndexOf(':')); var address = _session.Cluster.Configuration.AddressTranslator.Translate( new IPEndPoint(IPAddress.Parse(hostName), _session.Cluster.Configuration.ProtocolOptions.Port)); var host = _session.Cluster.GetHost(address); statement.PreferredHost = host; return(statement); }
internal override IStatement GetIStatement(GraphOptions options) { var parameters = ValuesDictionary ?? Values; IStatement stmt; if (parameters != null) { var jsonParams = JsonConvert.SerializeObject(parameters, GraphSON1ContractResolver.Settings); stmt = new TargettedSimpleStatement(Query, jsonParams); } else { stmt = new TargettedSimpleStatement(Query); } //Set Cassandra.Statement properties if (Timestamp != null) { stmt.SetTimestamp(Timestamp.Value); } var readTimeout = ReadTimeoutMillis != 0 ? ReadTimeoutMillis : options.ReadTimeoutMillis; if (readTimeout <= 0) { // Infinite (-1) is not supported in the core driver, set an arbitrarily large int readTimeout = int.MaxValue; } return(stmt .SetIdempotence(false) .SetConsistencyLevel(ConsistencyLevel) .SetReadTimeoutMillis(readTimeout) .SetOutgoingPayload(options.BuildPayload(this))); }
public void Should_Yield_Child_Hosts_When_No_Preferred_Host_Defined() { var lbp = new DseLoadBalancingPolicy(new TestLoadBalancingPolicy()); var statement = new TargettedSimpleStatement("Q"); var hosts = lbp.NewQueryPlan(null, statement); CollectionAssert.AreEqual( new[] { "101.0.0.0:9042", "102.0.0.0:9042" }, hosts.Select(h => h.Address.ToString())); }
private IEnumerable <Host> YieldPreferred(string keyspace, TargettedSimpleStatement statement) { yield return(statement.PreferredHost); foreach (var h in _childPolicy.NewQueryPlan(keyspace, statement)) { yield return(h); } }
public void Should_Set_Distance_For_Preferred_Host_To_Local() { var lbp = new DseLoadBalancingPolicy(new TestLoadBalancingPolicy(HostDistance.Ignored)); Assert.AreEqual(HostDistance.Ignored, lbp.Distance(new Host(new IPEndPoint(200L, 9042), ReconnectionPolicy))); var statement = new TargettedSimpleStatement("Q"); // Use 201 as preferred statement.PreferredHost = new Host(new IPEndPoint(201L, 9042), ReconnectionPolicy); lbp.NewQueryPlan(null, statement); Assert.AreEqual(HostDistance.Local, lbp.Distance(statement.PreferredHost)); }
public void Should_Yield_Preferred_Host_First() { var lbp = new DseLoadBalancingPolicy(new TestLoadBalancingPolicy()); var statement = new TargettedSimpleStatement("Q"); statement.PreferredHost = new Host(new IPEndPoint(201, 9042), ReconnectionPolicy); var hosts = lbp.NewQueryPlan(null, statement); CollectionAssert.AreEqual( new[] { "201.0.0.0:9042", "101.0.0.0:9042", "102.0.0.0:9042" }, hosts.Select(h => h.Address.ToString())); }
internal override IStatement GetIStatement(GraphOptions options) { string jsonParams = null; if (_valuesDictionary != null) { jsonParams = JsonConvert.SerializeObject(_valuesDictionary); } else if (_values != null) { jsonParams = JsonConvert.SerializeObject(_values); } IStatement stmt; if (jsonParams != null) { stmt = new TargettedSimpleStatement(_query, jsonParams); } else { stmt = new TargettedSimpleStatement(_query); } //Set Cassandra.Statement properties if (Timestamp != null) { stmt.SetTimestamp(Timestamp.Value); } var readTimeout = ReadTimeoutMillis != 0 ? ReadTimeoutMillis : options.ReadTimeoutMillis; if (readTimeout <= 0) { // Infinite (-1) is not supported in the core driver, set an arbitrarily large int readTimeout = int.MaxValue; } return stmt .SetIdempotence(false) .SetConsistencyLevel(ConsistencyLevel) .SetReadTimeoutMillis(readTimeout) .SetOutgoingPayload(options.BuildPayload(this)); }
private IEnumerable<Host> YieldPreferred(string keyspace, TargettedSimpleStatement statement) { yield return statement.PreferredHost; foreach (var h in _childPolicy.NewQueryPlan(keyspace, statement)) { yield return h; } }