I am using the Datastax C# driver (2.0.3) to access my Cassandra cluster (2.0.8) hosted on a VM in Azure.
I have a long running process with reads or writes statements using a session object. If 5 minutes passes without any statements to the open session, then the following statement will fail with a NoHostAvailableException.
This code reproduces the problem:
static void Main(string[] args)
{
// Arrange
var _cluster = Cluster();
var session = _cluster.Connect();
var keyspace = "nohostavailabletest";
session.CreateKeyspaceIfNotExists(keyspace);
session.ChangeKeyspace(keyspace);
session.Execute(@"CREATE TABLE IF NOT EXISTS test (customer_id text, PRIMARY KEY (customer_id));");
session.Execute("INSERT INTO \"test\"(\"customer_id\") VALUES ('myCustomer');");
// Act
Console.WriteLine("Cassandra ready for time out test...");
var query = "select * from test;";
session.Execute(query);
Console.WriteLine("Read from Cassandra");
Thread.Sleep(5*60*1000);
session.Execute(query); // This execution will throw an NoHostAvailableException
Console.WriteLine("This point is never reach because of NoHostAvailableException");
}
private static Cluster Cluster()
{
return Cassandra.Cluster.Builder()
.AddContactPoints(new[] { "insertYourClusterIpHere" })
.WithPort(9042)
.Build();
}Am I doing anything wrong? Or is there some kind of "keep alive" feature in the driver?
To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-u...@lists.datastax.com.
$ if exist csharp-driver rmdir /S /Q csharp-driver
$ git clone https://github.com/datastax/csharp-driver.git --branch master --single-branch
$ msbuild.exe /v:m /property:Configuration=Release csharp-driver\src\Cassandra.sln
To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-u...@lists.datastax.com.
To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-u...@lists.datastax.com.
To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-user+unsub...@lists.datastax.com.
We are also having issues like this after rewriting all our queries to prepared statements. No problems before when using batch writes and simple statements for reads.
At some point in time all queries from that applikation times out, while other applikations, that use the same cluster, works fine.
Applikation restart is also bringing the applikation up and running again in our case.
We have yet to track down if this problem relates to a single prepared statement beeing inactive, but that could very well be the case.
To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-u...@lists.datastax.com.
Some firewalls and network devices kill connections that have been idling for some time.
To avoid that, a heartbeat functionality should be implemented that makes a request to the Cassandra server after a configurable interval passed since the last request.
This functionality will be common in all DataStax drivers.
The setting is included in the PoolingOptions.
//Heartbeat after 50 seconds of idling Cluster.Builder() .AddContactPoints(hosts) .WithPoolingOptions( new PoolingOptions() .SetHeartBeatInterval(50000));