J
J
junart2014-08-24 00:44:24
CodeIgniter
junart, 2014-08-24 00:44:24

Phpcassa library - why does an error occur every time - with details?

Table structure:

CREATE TABLE posts_user (
  post_id  bigint,
  post_at  timestamp,
  user_id  bigint,
  PRIMARY KEY ((post_id), post_at)
)
WITH CLUSTERING ORDER BY (post_at DESC) AND COMPACT STORAGE;

PHP code:
<?php
require_once(__DIR__.'/phpcassa/lib/autoload.php');
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;

class Cassandra {

        public $c;

        function __construct() {
            $pool = new ConnectionPool('<b>feed</b>', array('127.0.0.1:9160'));
            $this->c = new ColumnFamily($pool, '<b>posts_user</b>');
        }

        public function insert(){
            $num =  rand(1, 500);
            $this->c->insert($num, array('post_at' => time(), 'user_id' => '1')); //Здесь возникает ошибка при добавлении
            //$results = $this->c->get("1");
        }
}
?>

Inserting an entry via the console (an entry was successfully added):
cqlsh:feed> INSERT INTO posts_user (post_at, user_id, post_id) VALUES (1408827330, 3, 169);

Error in PHP when using the insert() function:
Fatal error: Uncaught exception 'cassandra\InvalidRequestException' in /home/who/public_html/application/libraries/phpcassa/lib/Thrift/Base/TBase.php:206 Stack trace: #0 /home/who/public_html/application/libraries /phpcassa/lib/cassandra/Cassandra.php(3859): Thrift\Base\TBase->_read('Cassandra_batch...', Array, Object(Thrift\Protocol\TBinaryProtocolAccelerated)) #1 /home/who/public_html/ application/libraries/phpcassa/lib/cassandra/Cassandra.php(939): cassandra\Cassandra_batch_mutate_result->read(Object(Thrift\Protocol\TBinaryProtocolAccelerated)) #2 /home/who/public_html/application/libraries/phpcassa/lib/ cassandra/Cassandra.php(901): cassandra\CassandraClient->recv_batch_mutate() #3 [internal function]: cassandra\CassandraClient->batch_mutate(Array,1) #4 /home/who/public_html/application/libraries/phpcassa/lib/phpcassa/Connection/ConnectionPool.php(264): call_user_func_array(Array, Array) #5 /home/who/public_html/application/libraries/phpcassa /lib/phpcassa/AbstractColumnFamily.php(686): phpc in /home/who/public_html/application/libraries/phpcassa/lib/Thrift/Base/TBase.php on line 206

The section of code where the error occurred:
// File TBase.php:206
 $this->$var = new $class();

// Переменная $class - \cassandra\KsDef187\cassandra\InvalidRequestException

phpcassa help:
link
phpcassa library downloaded from the resource:
https://github.com/thobbs/phpcassa
Installed version of Cassandra:
[cqlsh 4.1.1 | Cassandra 2.0.9 | CQL spec 3.1.1 | Thrift protocol 19.39.0]

Perhaps it's a Cassandra subtlety (cache, no additional parameters set when creating the posts_user column ), but the request worked through the console. There is also an assumption that somewhere the PHP script takes a long time to execute and throws an exception. In addition, I did not understand what the COMPACT STORAGE parameter in CREATE is for .
Thanks in advance to everyone who will help with this task, spent many days, did not reveal the reason ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1Michael1, 2014-08-24
@1Michael1

something prompts to me that a problem in a connection... at new ConnectionPool connection is not created yet. the connection is initialized when the insert itself passes
and since the connection cannot be initialized, it falls with the exception

A
Alexander, 2015-11-03
@akalend

use native protocol and CQL https://code.google.com/a/apache-extras.org/p/cass... or any other from www.planetcassandra.org/client-drivers-tools/#PHP and don't suffer
in general, there are bugs in Cassandra when a table was created by a trick and is used natively, the same when inserting data, those data are inserted by a trick into a table created from CQL or vice versa. You can see not all created fields, etc. Trift is considered an obsolete protocol and it is RECOMMENDED NOT to USE
ie. it is necessary to use either only a trift or only a native, otherwise there will be a solid rake and stones. And since there are no tools for the trift, you shouldn’t use it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question