Git Product home page Git Product logo

phpcassa's Introduction

phpcassa

Build Status

phpcassa is a PHP client library for Apache Cassandra.

  • Compatible with Cassandra 0.7 through 1.2
  • Optional C extension for improved performance

phpcassa is compatible with PHP 5.3+

phpcassa is open source under the MIT license.

Deprecated

At this point, phpcassa has been deprecated and will no longer be supported.

I suggest using the DataStax PHP driver located here: https://github.com/datastax/php-driver. It supports CQL, has many excellent features, and is well maintained.

Documentation

While this README includes some useful information, the official and more thorough documentation can be found here:

http://thobbs.github.com/phpcassa

Examples

You can find a few fully working example scripts in the examples/ directory.

Opening Connections

$pool = new ConnectionPool('Keyspace1');

or

$pool = new ConnectionPool('Keyspace1', array('localhost'));

Create a column family object

$users = new ColumnFamily($pool, 'Standard1');
$super = new SuperColumnFamily($pool, 'Super1');

Inserting

$users->insert('key', array('column1' => 'value1', 'column2' => 'value2'));

Querying

$users->get('key');
$users->multiget(array('key1', 'key2'));

Removing

$users->remove('key1'); // removes whole row
$users->remove('key1', 'column1'); // removes 'column1'

Other

$users->get_count('key1'); // counts the number of columns in row 'key1'
$users->get_range('key1', 'key9'); // gets all rows with keys between '1' and '9'

Using the C Extension

The C extension is crucial for phpcassa's performance.

You need to configure and make to be able to use the C extension.

Note: if checkinstall is available, run sudo checkinstall in place of sudo make install.

cd ext/thrift_protocol
phpize
./configure
make
sudo make install

Add the following line to your php.ini file:

extension=thrift_protocol.so

Getting Help

phpcassa's People

Contributors

coolcold avatar hoan avatar karlhiramoto avatar lafka avatar maescool avatar maxwheeler avatar mcd-php avatar oberman avatar portsnap avatar ricardclau avatar thobbs avatar ucryptex avatar udat avatar wajamjenkins avatar winglian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpcassa's Issues

DateType insert giving error

When you try to insert value to a DateType column with milliseconds value, it gives error: Expected 8 or 0 byte long for date

This patch fixes the problem:

0.8.a.2/columnfamily.php    2012-01-12 22:59:12.000000000 +0530
new/columnfamily.php    2012-03-21 12:40:53.000000000 +0530
@@ -771,7 +771,7 @@

     private static $TYPES = array('BytesType' => 1, 'LongType' => 1, 'IntegerType' => 1,
                                   'UTF8Type' => 1, 'AsciiType' => 1, 'LexicalUUIDType' => 1,
-                                  'TimeUUIDType' => 1);
+                                  'TimeUUIDType' => 1, 'DateType' => 1);

     private static function extract_type_name($type_string) {
         if ($type_string == null or $type_string == '')
@@ -995,7 +995,7 @@
     }

     private function pack($value, $data_type) {
-        if ($data_type == 'LongType')
+        if (($data_type == 'LongType') || ($data_type == 'DateType'))
             return self::pack_long($value);
         else if ($data_type == 'IntegerType')
             return pack('N', $value); // Unsigned 32bit big-endian

Column value is required

Hi,

A cassandra_InvalidRequestException is raised in phpcassa\thrift\Thrift.php:574 when I try to set a null value to a column.

This used to work but it doesn't anymore, I don't know what changes I've made that can have this effect.

I perform a batch_insert($array);

array(41) {
[1]=>
array(4) {
[1]=>
NULL
[12821]=>
NULL
[16574]=>
NULL
[16575]=>
NULL
}
[12818]=>
array(4) {
[12818]=>
NULL
[16577]=>
NULL
[16578]=>
NULL
[16579]=>
NULL
}
[12819]=>
array(1) {
[12819]=>
NULL
}
[12817]=>
array(3) {
[12820]=>
NULL
[16543]=>
NULL
[16544]=>
NULL
}
[12820]=>
array(1) {
[16545]=>
NULL
}
[12821]=>
array(2) {
[16546]=>
NULL
[16591]=>
NULL
}
[12822]=>
array(1) {
[16547]=>
NULL
}
[12823]=>
array(1) {
[16548]=>
NULL
}
[12824]=>
array(1) {
[16549]=>
NULL
}
[12825]=>
array(1) {
[16550]=>
NULL
}
[12826]=>
array(1) {
[16551]=>
NULL
}
[12827]=>
array(1) {
[16552]=>
NULL
}
[12828]=>
array(2) {
[16553]=>
NULL
[16561]=>
NULL
}
[12829]=>
array(1) {
[16554]=>
NULL
}
[12830]=>
array(1) {
[16555]=>
NULL
}
[12831]=>
array(1) {
[16556]=>
NULL
}
[12832]=>
array(1) {
[16557]=>
NULL
}
[12833]=>
array(1) {
[16558]=>
NULL
}
[12834]=>
array(4) {
[16559]=>
NULL
[16560]=>
NULL
[16562]=>
NULL
[16585]=>
NULL
}
[12835]=>
array(1) {
[16563]=>
NULL
}
[12836]=>
array(1) {
[16564]=>
NULL
}
[12837]=>
array(2) {
[16565]=>
NULL
[16566]=>
NULL
}
[12838]=>
array(1) {
[16567]=>
NULL
}
[12839]=>
array(1) {
[16568]=>
NULL
}
[12840]=>
array(1) {
[16569]=>
NULL
}
[12841]=>
array(1) {
[16570]=>
NULL
}
[12842]=>
array(1) {
[16571]=>
NULL
}
[12848]=>
array(1) {
[16572]=>
NULL
}
[12849]=>
array(1) {
[16573]=>
NULL
}
[12851]=>
array(1) {
[16580]=>
NULL
}
[12852]=>
array(1) {
[16581]=>
NULL
}
[12853]=>
array(1) {
[16582]=>
NULL
}
[12854]=>
array(1) {
[16583]=>
NULL
}
[12855]=>
array(1) {
[16584]=>
NULL
}
[12856]=>
array(1) {
[16586]=>
NULL
}
[12857]=>
array(1) {
[16587]=>
NULL
}
[12858]=>
array(4) {
[16588]=>
NULL
[16593]=>
NULL
[16594]=>
NULL
[16595]=>
NULL
}
[12859]=>
array(1) {
[16589]=>
NULL
}
[12860]=>
array(1) {
[16590]=>
NULL
}
[12861]=>
array(1) {
[16592]=>
NULL
}
[12862]=>
array(1) {
[16596]=>
NULL
}
}

It doesn't work better with a simple insert. I'm using Cassandra 0.8.6, Thrift 19.16.0, and phpCassa 0.8.a.2

Any Ideas ?

Problem to get a slice of columns under super columns

I have problem to read a slice with columns under a super column. The column family has Comparator Type = LongType and Subcomparator Type = TimeUUIDType.
When i try to use get like this ($nextCol is a TimeUUID where to start read the columns.):
$columns = $this->family_feedsort->get($UserID, NULL, $nextCol, "", TRUE, $numberOfColumns, $Id);
I get the following error: TimeUUID should be 16 or 0 bytes (8)

When i do it on another column family with out super columns it works perfect.

I made a quick fix in columnfamily.php that solves it, but probably there is a better way to do it.
When getting a slice from columns under a super column, create_slice_predicate use the property is_super to determine if it is super or normal columns, but is_super tells if it is a super column family or not. So if you submit a $super_column parameter it is normal columns that are read under the super column.

public function get($key,
                    $columns=null,
                    $column_start="",
                    $column_finish="",
                    $column_reversed=False,
                    $column_count=self::DEFAULT_COLUMN_COUNT,
                    $super_column=null,
                    $read_consistency_level=null) {

    $column_parent = $this->create_column_parent($super_column);
    $predicate = $this->create_slice_predicate($columns, $column_start, $column_finish,
                                               $column_reversed, $column_count, $super_column != NULL); //---- changed here

    $resp = $this->pool->call("get_slice",
        $this->pack_key($key),
        $column_parent,
        $predicate,
        $this->rcl($read_consistency_level));

    if (count($resp) == 0)
        throw new cassandra_NotFoundException();

    return $this->supercolumns_or_columns_to_array($resp);
}


private function create_slice_predicate($columns, $column_start, $column_finish,
                                               $column_reversed, $column_count, $isSuper = NULL) { //---- changed here

    if ($isSuper == NULL) //---- changed here
    {
        $isSuper = $this->is_super;
    }
    else
    {
        $isSuper = !$isSuper;
    }

    $predicate = new cassandra_SlicePredicate();
    if ($columns !== null) {
        $packed_cols = array();
        foreach($columns as $col)
            $packed_cols[] = $this->pack_name($col, $isSuper);//---- changed here
        $predicate->column_names = $packed_cols;
    } else {
        if ($column_start != null and $column_start != '')
            $column_start = $this->pack_name($column_start,
                                             $isSuper, //---- changed here
                                             self::SLICE_START);
        if ($column_finish != null and $column_finish != '')
            $column_finish = $this->pack_name($column_finish,
                                              $isSuper, //---- changed here
                                              self::SLICE_FINISH);

        $slice_range = new cassandra_SliceRange();
        $slice_range->count = $column_count;
        $slice_range->reversed = $column_reversed;
        $slice_range->start  = $column_start;
        $slice_range->finish = $column_finish;
        $predicate->slice_range = $slice_range;
    }
    return $predicate;
}

Not connecting in Hiphop-PHP

When I try and connect through PHPCassa in HipHop-PHP or hphpi running the following test code:

$servers[0] = array('host' => '10.10.1.55', 'port' => 9160);
try {
$conn = new Connection('articles', $servers);
}
catch (Exception $e) {
print_r($e);
}

I get the following exception thrown:

NoServerAvailable Object
(
[message:protected] => An attempt was made to connect to every server twice, but all attempts failed. The last error was: exception 'TTransportException' with message 'TSocket: Could not write 33 bytes 10.10.1.55:9160' in /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/thrift/transport/TSocket.php:293
Stack trace:
#0 /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/thrift/transport/TFramedTransport.php(175): TSocket->write()
#1 (): TFramedTransport->flush()
#2 /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/thrift/packages/cassandra/Cassandra.php(1001): thrift_protocol_write_binary()
#3 /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/thrift/packages/cassandra/Cassandra.php(991): CassandraClient->send_describe_version()
#4 /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/connection.php(73): CassandraClient->describe_version()
#5 /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/connection.php(211): ConnectionWrapper->__construct()
#6 /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/connection.php(199): ConnectionPool->make_conn()
#7 /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/connection.php(363): ConnectionPool->__construct()
#8 /home/www/sites-nosync/www/index.php(17): Connection->__construct()
#9 {main}

[code:protected] => 0
[file:protected] => /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/connection.php
[line:protected] => 222
[trace:protected] => Array
    (
        [0] => Array
            (
                [file] => /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/connection.php
                [line] => 199
                [function] => make_conn
                [class] => ConnectionPool
                [object] => Connection Object
                    (
                        [keyspace] => articles
                        [servers:private] => Array
                            (
                                [0] => 10.10.1.55:9160
                            )

                        [pool_size:private] => 5
                        [timeout:private] => 
                        [recycle:private] => 10000
                        [max_retries:private] => 5
                        [credentials:private] => 
                        [framed_transport:private] => 1
                        [queue:private] => Array
                            (
                            )

                        [keyspace_description:private] => 
                        [send_timeout] => 5000
                        [recv_timeout] => 5000
                        [stats] => Array
                            (
                                [created] => 0
                                [failed] => 2
                                [recycled] => 0
                            )

                        [list_position] => 0
                    )

                [type] => ->
                [args] => Array
                    (
                    )

            )

        [1] => Array
            (
                [file] => /home/www/sites-nosync/thobbs-phpcassa-7f07ea0/connection.php
                [line] => 363
                [function] => __construct
                [class] => ConnectionPool
                [object] => Connection Object
                    (
                        [keyspace] => articles
                        [servers:private] => Array
                            (
                                [0] => 10.10.1.55:9160
                            )

                        [pool_size:private] => 5
                        [timeout:private] => 
                        [recycle:private] => 10000
                        [max_retries:private] => 5
                        [credentials:private] => 
                        [framed_transport:private] => 1
                        [queue:private] => Array
                            (
                            )

                        [keyspace_description:private] => 
                        [send_timeout] => 5000
                        [recv_timeout] => 5000
                        [stats] => Array
                            (
                                [created] => 0
                                [failed] => 2
                                [recycled] => 0
                            )

                        [list_position] => 0
                    )

                [type] => ->
                [args] => Array
                    (
                        [0] => articles
                        [1] => Array
                            (
                                [0] => 10.10.1.55:9160
                            )

                        [2] => 1
                        [3] => 5
                        [4] => 5000
                        [5] => 5000
                        [6] => 10000
                        [7] => 
                        [8] => 1
                    )

            )

        [2] => Array
            (
                [file] => /home/www/sites-nosync/www/index.php
                [line] => 17
                [function] => __construct
                [class] => Connection
                [object] => Connection Object
                    (
                        [keyspace] => articles
                        [servers:private] => Array
                            (
                                [0] => 10.10.1.55:9160
                            )

                        [pool_size:private] => 5
                        [timeout:private] => 
                        [recycle:private] => 10000
                        [max_retries:private] => 5
                        [credentials:private] => 
                        [framed_transport:private] => 1
                        [queue:private] => Array
                            (
                            )

                        [keyspace_description:private] => 
                        [send_timeout] => 5000
                        [recv_timeout] => 5000
                        [stats] => Array
                            (
                                [created] => 0
                                [failed] => 2
                                [recycled] => 0
                            )

                        [list_position] => 0
                    )

                [type] => ->
                [args] => Array
                    (
                        [0] => articles
                        [1] => Array
                            (
                                [0] => Array
                                    (
                                        [host] => 10.10.1.55
                                        [port] => 9160
                                    )

                            )

                    )

            )

    )

)

I should perhaps add that the server is definately up and I don't get this problem using PHPCassa with Apache/PHP or using SimpleCassie with Hiphop

Call to a member function set_keyspace() on a non-object

After updating to the latest version the app is crashing with Call to a member function set_keyspace() on a non-object in connection.php.

Scanning through the code it seems that the ConnectionWrapper object is trying to call set_keyspace on its member $client before it has been set.

moving Line:90 $this->client = $client; to Line:71 fixed this error.

warning generated in cf->get when columns=null and column_start populated

Maybe this is by design, but just incase:

Sample code:

        $cf = new ColumnFamily(getConn(), 'entity_relations');
        $rows = $cf->get($uid, $columns=null, $column_start=array('foo:')); 

Error:
PHP Warning: mb_detect_encoding() expects parameter 1 to be string, array given in /mnt/hgfs/workspace/core/include/columnfamily.php on line 865
PHP Warning: utf8_encode() expects parameter 1 to be string, array given in /mnt/hgfs/workspace/core/include/columnfamily.php on line 866"

Idea is to list all columns that start with "foo:"

How to use secondary index in phpcassa

hello:

I have create the CF like this:
//create column family users with comparator = UTF8Type and
// column_metadata = [{column_name: name, validation_class:UTF8Type},
// {column_name: email,validation_class:UTF8Type},
// {column_name: age, validation_class: LongType,index_type: KEYS}];

and i have give some value like:
[default@test] get users wher age=30;
RowKey: 7468697264
=> (column=age, value=30, timestamp=-1298750687)
RowKey: 6669727374
=> (column=age, value=30, timestamp=-1481259961)

then how can i use it by phpCassa like above?
i can't find any example code on google, pls help me, thx

Invalid bytes remaining after an end-of-component at component1

I'm using the Composite branch of phpcassa.
I have a CF with composite column names:

ColumnFamily: MyCF
  Key Validation Class: org.apache.cassandra.db.marshal.UTF8Type
  Default column value validator: org.apache.cassandra.db.marshal.UTF8Type
  Columns sorted by: org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.AsciiType,org.apache.cassandra.db.marshal.IntegerType)
  Row cache size / save period in seconds / keys to save : 0.0/0/all
  Row Cache Provider: org.apache.cassandra.cache.SerializingCacheProvider
  Key cache size / save period in seconds: 200000.0/14400
  GC grace seconds: 864000
  Compaction min/max thresholds: 4/32
  Read repair chance: 0.1
  Replicate on write: true
  Bloom Filter FP chance: default
  Built indexes: []
  Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
  Compression Options:
    chunk_length_kb: 64
    sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor

I occasionally get the following exception when trying to read data from it:

exception 'cassandra_InvalidRequestException' with message
'Invalid bytes remaining after an end-of-component at component1' in /phpcassa/thrift/packages/cassandra/Cassandra.php:256\nStack trace:
#0 /phpcassa/thrift/packages/cassandra/Cassandra.php(256): thrift_protocol_read_binary(Object(TBinaryProtocolAccelerated), 'cassandra_Cassa...', false)
#1 /phpcassa/thrift/packages/cassandra/Cassandra.php(229): CassandraClient->recv_get_slice()
#2 [internal function]: CassandraClient->get_slice('6034-28141406', Object(cassandra_ColumnParent), Object(cassandra_SlicePredicate), 2)
...

The command I'm running is:

$keys = array(
  serialize(array('total', 12345))
);
$cf->get('6034-28141406', $keys);

Sysmanager should support renaming KS/CF

As the title say, it would be nice if sysmanager could support renaming a KS or CF. I was ready to do it until I realized the two functions system_rename_column_family and system_rename_keyspace weren't in Cassandra.php. I'm not sure if generating these file again from thrift would do it, and then we just have to modify sysmanager to support it ?

Thanks!

Expose hook for updating ConnectionPool KsDef

This allows the ksdef/cfdefs to be updated when a schema change occurs. This would primarily make writing test suites against phpcassa easier, although it could theoretically be used under normal circumstances.

Expose truncate() in sysmanager

Shouldn't be too hard :)

Also not sure if its possible but add a drop_index function and maybe a get_index_list() or something like that to get all secondary index created for a CF if it's possible.

Typo in sysmanager

public function describe_keyspaces() {
    return $this->client->describe_keyspace();
}

should be:

public function describe_keyspaces() {
    return $this->client->describe_keyspaces();
}

:)

wrong ELF class

hello everyone.

I've installed the c extension but it gives me this warning when I start lampp, I don't know if somebody else got it.

Warning: PHP Startup: Unable to load dynamic library '/opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/thrift_protocol.so' - /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/thrift_protocol.so: wrong ELF class: ELFCLASS64 in Unknown on line 0

I looked google for some help and it says: "wrong ELF class <-- meaning you installed a 32 bit appilication on a 64 bit system or the way around."

How can I solve it? thanks for any help.

how to make conditions inquires in phpcassa

if I can use phpcassa to do the search like this "condition1<X<condition2" on a indexed CF?
I have learn from the document, but i didn't found any prompt on the question

multiget greater than $buffer_size botches keys

Just wanted to report a bug in the latest version of PHPCassa. I am using Cassandra 0.8 and php 5.3.3

If you issue a multiget with more keys than $buffer_size (by default, 16), PHPCassa will loose all of the key values for the rows that are returned.

The problem is that when count($keys) is greater $buffer_size, PHPCassa will issue multiple calls to cassandra and then merge the results together with array_merge. array_merge, however, will reindex numeric non-string keys which causes the true key values to be lost[1].

The solution is to use the "+" operator instead of array_merge on lines 373 and 382 of columnfamily.php

$resp = $resp + $sub_resp;

I can submit a patch if you'd like, but the overall change is pretty tiny.

[1] See example 3 at http://us.php.net/manual/en/function.array-merge.php for more information

timed out reading 4 bytes

Remember that "old" issue with that error message :
TTransportException' with message 'TSocket: timed out reading 4 bytes from 10.231.102.123:9160' in /home/user/phpcassa/thrift/transport/TSocket.php:268

Looks like its back with the new thrift version that you recently commited. Anyone else running into this issue ?

Wrong documentation in sysmanager

To create a keyspace, you need to specify strategy_class, not strategy_name :)

/**
 * Creates a new keyspace.
 *
 * Example usage:
 * <code>
 * $sys = SystemManager();
 * $attrs = array("replication_factor" => 1,
 *                "strategy_name" => "org.apache.cassandra.locator.SimpleStrategy");

Should be

/**
 * Creates a new keyspace.
 *
 * Example usage:
 * <code>
 * $sys = SystemManager();
 * $attrs = array("replication_factor" => 1,
 *                "strategy_class" => "org.apache.cassandra.locator.SimpleStrategy");

Using C extension "thrift_protocol" causes timestamp corruption

With C extension "thrift_protocol" enabled all timestamps generated with CassandraUtil::get_time() are corrupted to become negative numbers. Columns were not able to be removed either. I could make it work by passing my own timestamp generated with time(), but that didn't give enough precision and there is also no way to pass a custom timestamp into the remove() function.

Once thrift_protocol was disabled in php.ini everything worked perfectly without the need to pass in my own timestamps at all.

Support batch counter adjustments

batch_mutate accepts a set of ColumnOrSuperColumns, which can include CounterColumns and CounterSuperColumns for batch adjustments of counters.

->get($key) with non existing key

When I do a get with a key that doesn't exist. I get an error instead of a null result. Is there a way I can check if a key(row) exists or not.

thx

Stijnbe

Hanging on Consistency Failure

I'm not sure if I'm doing something wrong but for me when I attempt an operation with a consistency level higher then is possible eg: consistency level ALL when it is only possible to do a consistency level QUORUM I think it should fail and throw an exception but instead it seems to hang for me, am I doing something wrong. I have a low timeout and retries set?

Any help appreciated.

Recursing too deep in ColumnFamilyIterator->next()

If a CF query results in many empty (tombstone) rows then next() will call itself too many times and fault with the following error.

Fatal error: Maximum function nesting level of '100' reached, aborting! in /util/phpcassa/columnfamily.php on line 1222

Call Stack:

0.1746 10349728 5. ColumnFamilyIterator->next() /util/phpcassa/columnfamily.php:1231
0.1746 10349864 6. ColumnFamilyIterator->next() /util/phpcassa/columnfamily.php:1231
0.1746 10350000 7. ColumnFamilyIterator->next() /util/phpcassa/columnfamily.php:1231

The problem occurs on line 1229 below:

        if (count(current($this->current_buffer)) == 0)
        {
            # this is an empty row, skip it
            $key = key($this->current_buffer);
            $this->next();
        }

When there are lots of empty rows $this->next() keeps getting called until it goes too deep and dies.

insert from multiserver via PHPcassa

I installed and insert row_key on one server ok (server install cassandra), when I connect and insert from other remote server to cassandra then server install cassandra can't insert

Please help me, how to insert from multiserver to cassandra
Thks for reply

Fail to remove columns using C extension 'thrift_protocol' in CLI mode

Only method 'remove' in class 'ColumnFamily' do nothing.
When i disable 'thrift_protocol' in php.ini, method 'remove' is normal.
Environment:
Ubuntu Server 10.04
PHP 5.3.2-1ubuntu4.7 with Suhosin-Patch (cli) (built: Jan 12 2011 18:36:08)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
phpcassa-0.7.a.4

Cassandra_set_keyspace_result not found.

While initiating.ColumnFamily object...

PHP Fatal error:  Class '\cassandra\Cassandra_set_keyspace_result' not found in .../include/phpcassa/lib/thrift/packages/cassandra/cassandra.Cassandra.client.php on line 100
PHP Stack trace:
PHP   1. {main}() .../hostIpFraud2.php:0
PHP   2. phpcassa\ColumnFamily->__construct() /opt/...
PHP   3. phpcassa\Connection\ConnectionPool->describe_keyspace() .../include/phpcassa/lib/phpcassa/ColumnFamily.php:175
PHP   4. phpcassa\Connection\ConnectionPool->call() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:192
PHP   5. phpcassa\Connection\ConnectionPool->get() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:257
PHP   6. phpcassa\Connection\ConnectionPool->make_conn() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:163
PHP   7. phpcassa\Connection\ConnectionWrapper->__construct() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:125
PHP   8. phpcassa\Connection\ConnectionWrapper->set_keyspace() .../include/phpcassa/lib/phpcassa/Connection/ConnectionWrapper.php:53
PHP   9. cassandra\CassandraClient->set_keyspace() .../include/phpcassa/lib/phpcassa/Connection/ConnectionWrapper.php:71
PHP  10. cassandra\CassandraClient->recv_set_keyspace() .../include/phpcassa/lib/thrift/packages/cassandra/cassandra.Cassandra.client.php:76
PHP  11. thrift_protocol_read_binary() .../include/phpcassa/lib/thrift/packages/cassandra/cassandra.Cassandra.client.php:100

Fatal error: Class '\cassandra\Cassandra_set_keyspace_result' not found in .../include/phpcassa/lib/thrift/packages/cassandra/cassandra.Cassandra.client.php on line 100

Call Stack:
    0.0003     345052   1. {main}() .../hostIpFraud2.php:0
    0.9295   16955684   2. phpcassa\ColumnFamily->__construct() /opt/...
    0.9295   16956012   3. phpcassa\Connection\ConnectionPool->describe_keyspace() .../include/phpcassa/lib/phpcassa/ColumnFamily.php:175
    0.9295   16956116   4. phpcassa\Connection\ConnectionPool->call() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:192
    0.9295   16958080   5. phpcassa\Connection\ConnectionPool->get() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:257
    0.9295   16958132   6. phpcassa\Connection\ConnectionPool->make_conn() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:163
    0.9313   17236628   7. phpcassa\Connection\ConnectionWrapper->__construct() .../include/phpcassa/lib/phpcassa/Connection/ConnectionPool.php:125
    0.9366   18080736   8. phpcassa\Connection\ConnectionWrapper->set_keyspace() .../include/phpcassa/lib/phpcassa/Connection/ConnectionWrapper.php:53
    0.9366   18080736   9. cassandra\CassandraClient->set_keyspace() .../include/phpcassa/lib/phpcassa/Connection/ConnectionWrapper.php:71
    0.9373   18093400  10. cassandra\CassandraClient->recv_set_keyspace() .../include/phpcassa/lib/thrift/packages/cassandra/cassandra.Cassandra.client.php:76
    0.9373   18093600  11. thrift_protocol_read_binary() .../include/phpcassa/lib/thrift/packages/cassandra/cassandra.Cassandra.client.php:100

Little cleanup

In the ConnectionPool constructor, to permute the servers list, you can just do shuffle($servers); instead of that permutating loop thing :)

Cannot install phpcassa 0.7.a.4

I get the following error when I 'make' phpcassa.

In file included from /usr/include/php5/main/php.h:34,
from /usr/phpcassa-0.7.a.4/thrift/ext/thrift_protocol/php_thrift_protocol.cpp:81:
/usr/include/php5/Zend/zend.h:320: error: ‘zvalue_value’ does not name a type
In file included from /usr/include/php5/Zend/zend_API.h:30,
from /usr/include/php5/main/php.h:38,
from /usr/phpcassa-0.7.a.4/thrift/ext/thrift_protocol/php_thrift_protocol.cpp:81:
/usr/include/php5/Zend/zend_execute.h: In function ‘int i_zend_is_true(zval*)’:
/usr/include/php5/Zend/zend_execute.h:91: error: ‘struct _zval_struct’ has no member named ‘value’
/usr/include/php5/Zend/zend_execute.h:94: error: ‘struct _zval_struct’ has no member named ‘value’

This is my php -version output:
PHP 5.3.3-1ubuntu9.3 with Suhosin-Patch (cli) (built: Jan 12 2011 16:08:14)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Long running process hang when a node OOM

We have a 20 nodes 0.7.4 cluster. We have over 500 long running php process (gearman job) that read and write to cassandra. When one node goes down (not by normal shutdown but OOM), all php process start to use 100% CPU and doesn't do anything anymore. We are thinking that they get stuck in a while loop in the code somewhere because the process doesn't do anything. It could be a thrift related issue. I'm thinking that when the socket is not closed properly on the cassandra server side (such as when an OOM happen), thrift doesn't know the socket is killed and wait for data to be read from that socket still. You can check the PHP doc for feof here: http://ca3.php.net/manual/en/function.feof.php to see that feof() function have a similar issue if a socket is not closed by the server, feof() will hang. Unfortunatly, there is no feof() in thrift code so that doesn't help, but there must be something else similar. If someone confirm this is a thrift issue, I'm gonna post on thrift jira instead!

To reproduce:

  • Start a cassandra cluster with a few nodes.
  • Setup a few PHP scripts that stay running
  • Makes these PHP process read/write to cassandra
  • Make one or more cassandra node OOM
  • See CPU usage peak like crazy

Thank you!

sysmanager is missing drop_index function

Not exactly sure if it's the right way to do this but it seems to work :P If its done correctly let me know if you want a pull request or you can just commit it :)

Thank you!

    /**
     * Drop an index from a column family.
     *
     * Example usage:
     *
     * <code>
     * $sys = new SystemManager();
     * $sys->drop_index("Keyspace1", "Users", "name");
     * </code>
     *
     * @param string $keyspace the name of the keyspace containing the column family
     * @param string $column_family the name of the column family
     * @param string $column the name of the column to drop the index from
     */
    public function drop_index($keyspace, $column_family, $column) {
        $matched = false;       
        $this->client->set_keyspace($keyspace);
        $cfdef = $this->get_cfdef($keyspace, $column_family);       
        $col_meta = $cfdef->column_metadata;

        for ($i = 0; $i < count($col_meta); $i++) {
            $col = $col_meta[$i];           
            if ($col->name == $column) {
                unset($col_meta[$i]);
                $cfdef->column_metadata = $col_meta;
                $matched = true;
                break;
            }
        }

        if ($matched) {
            $this->client->system_update_column_family($cfdef);
        }
    }

ConnectionPool optimization

Let's say we have 20 servers, we want a pool with 5 random server in it for a user that load a page and need to do a few requests to cassandra. The code currently will create a pool with 5 connections, then we can start doing read/write. The thing is, 5 connection is just an approximate number and we have no clue when doing the connection pool if the page will do 2 request or 50, so the 5 connection might not even get used before the php process die. We did some modification to phpcassa to optimize this. We have creating and adding the connection in connection pool as needed until we reach the queue_size, so no connection get created if they never get used. I would send a pull request but since I'm a git noob, I will do it here. I could send you (thobbs) an SVN patch on IRC or email if that help:

Added to variable to ConnectionWrapper class:
public $transport;
public $credentials;

And modified these 2 methods as follow:

public function __construct($keyspace,
$server,
$credentials=null,
$framed_transport=True,
$send_timeout=null,
$recv_timeout=null)
{
$this->server = $server;
$server = explode(':', $server);
$host = $server[0];
if(count($server) == 2)
$port = (int)$server[1];
else
$port = self::DEFAULT_PORT;
$socket = new TSocket($host, $port, true);

    if($send_timeout) $socket->setSendTimeout($send_timeout);
    if($recv_timeout) $socket->setRecvTimeout($recv_timeout);

    if($framed_transport) {
        $this->transport = new TFramedTransport($socket, true, true);
    } else {
        $this->transport = new TBufferedTransport($socket, 1024, 1024);
    }

$this->credentials = $credentials;
    $this->keyspace = $keyspace;
    $this->op_count = 0;
}

public function get_client() {
if (!$this->client) {
       $client = new CassandraClient(new TBinaryProtocolAccelerated($this->transport));
       $this->transport->open();

       $server_version = explode(".", $client->describe_version());
       $server_version = $server_version[0];
       if ($server_version < self::LOWEST_COMPATIBLE_VERSION) {
           $ver = self::LOWEST_COMPATIBLE_VERSION;
           throw new IncompatibleAPIException("The server's API version is too ".
               "low to be comptible with phpcassa (server: $server_version, ".
               "lowest compatible version: $ver)");
       }

       $client->set_keyspace($this->keyspace);

       if ($this->credentials) {
           $request = new cassandra_AuthenticationRequest(array("credentials" => $this->credentials));
           $client->login($request);
       }

       $this->client = $client;
}   

return $this->client;
}

And then the call function in ConnectionPool class is modified as follow (only mod is the $client = $conn->get_client(); line):

public function call() {
$args = func_get_args(); // Get all of the args passed to this function
$f = array_shift($args); // pull the function from the beginning

    $retry_count = 0;
    if ($this->max_retries == -1)
        $tries =  self::MAX_RETRIES;
    elseif ($this->max_retries == 0)
        $tries = 1;
    else
        $tries = $this->max_retries + 1;

    foreach (range(1, $tries) as $retry_count) {
        $conn = $this->get();

    $client = $conn->get_client();
        $conn->op_count += 1;
        try {
            $resp = call_user_func_array(array($client, $f), $args);
            $this->return_connection($conn);
            return $resp;
        } catch (cassandra_TimedOutException $toe) {
            $last_err = $toe;
            $this->handle_conn_failure($conn, $f, $toe, $retry_count);
        } catch (cassandra_UnavailableException $ue) {
            $last_err = $ue;
            $this->handle_conn_failure($conn, $f, $ue, $retry_count);
        } catch (TTransportException $tte) {
            $last_err = $tte;
            $this->handle_conn_failure($conn, $f, $tte, $retry_count);
        }
    }
    throw new MaxRetriesException("An attempt to execute $f failed $tries times.".
                                  " The last error was " . (string)$last_err);
}

Composite Type Support

Hey,
It will be great if we have native support for Composite Types in PHPCASSA. CQL also doesn't have a native support for Composite types.

Regards,
Tamil.s

how to make a secondary index on a supercolumn?

I wrote the code like below:

create column family Super1
with column_type = Super and comparator = UTF8Type and subcomparator = UTF8Type
and column_metadata = [ {column_name : x, validation_class : LongType, index_type:KEYS}, {column_name : y, validation_class : LongType, index_type:KEYS} ];

but it can't run under CLI mode, could somebody help me to modify it pls ...thx

Column name of 0 on insert causes exception

Inserting a column with the name of 0 and value of x results in

HP Fatal error: Uncaught exception 'TApplicationException' with message 'Required field 'name' was not present!

I traced this down to the following in function pack_name of columnfamily.php:

if ($value == null) {
return;

The value (column name) at this point is 0 which when compared to a null using '==' will evaluate to true and return no packed name.

The if statement should be if ( is_null($value)) or if ($value === null ) which will return the proper evaluation.
This occurs in several spots in the code.

Not sure why this wasn't found before, unless no one uses 0 for a column name, which I do for sequential columns.

Please comment.

Thanks

Documentation Error on Namespace.

The namespaces...

use phpcassa/ColumnFamily;
use phpcassa/ColumnSlice;
use phpcassa/Connection/ConnectionPool;

The slashes work the other way round for me.

use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;

Thanks. :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.