evseevnn-zz / php-cassandra-binary

PHP library for Cassandra database via a binary protocol.
http://evseevnn.github.io/php-cassandra-binary/
MIT License
69 stars 33 forks source link

Unavailable exception #29

Open trK54Ylmz opened 10 years ago

trK54Ylmz commented 10 years ago

Here is my code. I think there is a encoding/decoding or response parse problem.

require_once 'vendor/autoload.php';

$nodes = array(
    '127.0.0.1:9042' => array(
        'username'  => 'cassandra',
        'password'  => 'cassandra'
    )
);

try {
    $database = new evseevnn\Cassandra\Database($nodes, 'test');
    $database->connect();

    $users = $database->query('SELECT * FROM user');

    var_dump($users);
} catch (evseevnn\Cassandra\Exception\CassandraException $e) {
   echo $e->getMessage() . PHP_EOL;
}

And exception message is:

Unavailable exception. Error data: array (
  'consistency' => 2573153,
  'node' => 1852731252,
  'replica' => 543253352,
)

CQL shell output:

cqlsh:test> SELECT * FROM user;

 id                                   | activated | name         | password | regdate                  | status | username
--------------------------------------+-----------+--------------+----------+--------------------------+--------+----------
 ef8949f0-09da-11e4-8132-e76149b7842c |     False | Tarık Yılmaz | pass1234 | 2014-01-01 13:45:12+0200 |  False |    tarik

(1 rows)

and finally stack trace

#0 /home/tarik/Desktop/cass/index.php(15): evseevnn\Cassandra\Database->query('SELECT * FROM u...')
#1 {main}
LarsFronius commented 10 years ago

Hey @trK54Ylmz , how is your keyspace set up? Do you have a high replication factor and not all shards available? Its true that we should send a exception that guides you towards this error better. Can you confirm, that this can be the issue?

bborisovs commented 10 years ago

Hi @LarsFronius ,

I get the same problem :

Fatal error: Uncaught exception 'evseevnn\Cassandra\Exception\CassandraException' with message 'Unavailable exception. Error data: array ( 'consistency' => 2573153, 'node' => 1852731252, 'replica' => 543253352, )'

I have single node hosted on AWS; My test keyspace is : CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND durable_writes = true;

Any suggestions how to fix it? Should I reduce the replication factor ?

LarsFronius commented 10 years ago

With a single node, there is no way to fulfil your replication_factor of 3 replicas, so Cassandra throws back that the keyspace is unavailable, which is what you see - the Error data array though is quite misleading. With a replication_factor set to 1, you should be fine @bborisov

bborisovs commented 10 years ago

Thanks @LarsFronius that helped!

trK54Ylmz commented 10 years ago

@LarsFronius Thanks that helped me too. @evseevnn My problem solved. It was my test keyspace and replication_factor was set to 3. But,

Unavailable exception. Error data

in my opinion the error message should be better than this