Reputation: 1873
I'm new to cassandra but have a background of Nosql and high availability with other technologies. A few days ago I installed Cassandra 3.0 but it sounds Datastax php driver does not support it at all! So I downgraded to the 2.1.11 version and wrote a simple php script to query it using Datastax php-driver and it is working as it should be.
<?php
try {
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$keyspace = 'mykeysssspace';
$session = $cluster->connect($keyspace);
$statement = new Cassandra\SimpleStatement('SELECT userid, created_date, email FROM users');
$future = $session->executeAsync($statement);
$result = $future->get();
foreach ($result as $row) {
printf("userId: %s, email: %s\n", $row['userid'], $row['email']);
}
}catch(Exception $e) {
print $e->getMessage();
}
?>
Then I started two instance of Cassandra in the same machine (Ubuntu 11.10!) using different ip addresses. Then changed php code to:
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1', '127.0.0.2')
->build();
The problem is, as long as both instances are running everything works as expected and php outputs expected results. But when I stop one of the instances (no matter which) it gives
All hosts in current policy attempted and were either unavailable or failed
Even if I change it back to
$cluster = Cassandra::cluster()
->withContactPoints('running_instance_ip')
->build();
it gives me the same error. But cqlsh works in every scenario.
Is it something about the Datastax php driver?
Upvotes: 1
Views: 2587
Reputation: 9
You can try Retry policy
$retry_policy = new Cassandra\RetryPolicy\DowngradingConsistency();
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1','127.0.0.2')
->withRetryPolicy(new Cassandra\RetryPolicy\Logging($retry_policy))
->build();
$session = $cluster->connect("simplex");
$statement = $session->prepare("INSERT INTO playlists (id, song_id, artist, title, album)
VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)");
$options = array(
'consistency' => Cassandra::CONSISTENCY_ONE,
);
$session->execute($statement, $options);
Working for me.
Upvotes: 0
Reputation: 20741
In my case, I was running a test in an isolated environment with ONE node, but I was setting up the context with a replication factor of 2. So certain functions would fail with a timeout since it could never finish the wait for the other non-existent nodes to be updated in time.
So one solution is to make sure your replication factor is no larger than the number of nodes in your cluster (and yes, I fail to understand why Cassandra cannot just tell us: RF too large as an error.)
Upvotes: 0
Reputation: 4426
What replication factor are you using on your keyspace? If you're using RF=1, the error may be indicating that there aren't sufficient hosts alive to fulfill all ranges. Raising the replication factor would help solve that.
Upvotes: 1