I was contacted by Packt Publishing to be a part of the technical review team for the book on Learning Cassandra for Administrators. If you are interested in picking up on Cassandra check it out.
Category Archives: Cassandra
Getting started with the PHP Binary CQL client
I recently released a PHP client that implements the CQL binary protocol. I wanted to explain how to get started using the client and provide a walk through for getting this setup.
Installing
Not to much to install, just copy the code to your server and you should be ready to go. You do need to make sure that your PHP installation does meet the following requirements:
- 64 bit install of PHP
- iconv PHP module is installed (usually it is installed by default)
- mbstring PHP module is installed (usually it is installed by default)
- bcmath PHP module is installed (usually it is installed by default)
- snappy PHP module installed if you want to use compression
Walk through of simple_query.php
In the examples folder there is a simple_example.php, we’ll walk through that now:
Make sure we grab the autoloader.
require '../vendor/autoload.php';
Register the namespace with the class loader.
Now we are ready to instantiate the client, we are passing in the host and the port for the Cassandra server. CQL native transport port: 9042
$pbc = new \McFrazier\PhpBinaryCql\CqlClient('192.168.2.240', '9042');
Here we are configuring the connection, by passing in the version of CQL we will be using. This has to be done before you send a query to the server.
You can get a list of the available options by calling the getSupportedStartupOptions method.
You can configure compression by passing this option when configuring the connection. You need to have the PHP snappy module installed to use compression.
Ok, now that we have the connection configured lets create a query. We have to enter two parameters, the actual valid CQL text for the query, and the query consistency.
$response = $pbc->query($queryText, \McFrazier\PhpBinaryCql\CqlConstants::QUERY_CONSISTENCY_ONE);
You will get a response object back, you can view the data payload of the response object by calling the getData() method. I’ll make a separate blog post about the response object, and the information that is being returned.
object(stdClass)#24 (3) {
["rowMetadata"]=>
object(stdClass)#14 (4) {
["flags"]=>
int(1)
["columnsCount"]=>
int(4)
["globalTableSpec"]=>
object(stdClass)#15 (2) {
["keyspace"]=>
string(6) "system"
["tableName"]=>
string(16) "schema_keyspaces"
}
["columnSpec"]=>
array(4) {
[0]=>
object(stdClass)#10 (2) {
["columnName"]=>
string(13) "keyspace_name"
["optionId"]=>
int(13)
}
[1]=>
object(stdClass)#11 (2) {
["columnName"]=>
string(14) "durable_writes"
["optionId"]=>
int(4)
}
[2]=>
object(stdClass)#12 (2) {
["columnName"]=>
string(14) "strategy_class"
["optionId"]=>
int(13)
}
[3]=>
object(stdClass)#13 (2) {
["columnName"]=>
string(16) "strategy_options"
["optionId"]=>
int(13)
}
}
}
["rowsCount"]=>
int(1)
["rowsContent"]=>
array(1) {
[0]=>
object(stdClass)#9 (4) {
["keyspace_name"]=>
string(8) "ks_34512"
["durable_writes"]=>
bool(true)
["strategy_class"]=>
string(43) "org.apache.cassandra.locator.SimpleStrategy"
["strategy_options"]=>
string(26) "{"replication_factor":"1"}"
}
}
}
Let me know if you have any questions.
PHP Binary CQL
I have released an initial commit for a PHP client that implements the CQL binary protocol. This is a work in progress but it is functional enough for you to send queries to a Cassandra cluster. I’m building tests first then implementing the functionality, so I should have decent test coverage when complete. The tests require a running Cassandra cluster, and they create a keyspace, column family, and columns and clean up when the tests are complete.
I’ll do additional posts about the functionality as I get more features implemented, and tests created.
It’s on Github – https://github.com/rmcfrazier/phpbinarycql so please check it out and if you see any issues open bugs.
Example
Included is a very simple example that shows how to connect and send a query.
$pbc->addStartupOption('CQL_VERSION', '3.0.4');
$queryText = 'select * from system.schema_keyspaces';
$response = $pbc->query($queryText, \McFrazier\PhpBinaryCql\CqlConstants::QUERY_CONSISTENCY_ONE);
// view the entire response object
var_dump($response);
Cassandra and Hadoop and Hive, Oh my! (part 2)
This is part two to my previous post about adding Cassandra, Hadoop and Hive to the infrastructure at work. We are building a new web based application and wanted to add features that the current infrastructure would not support.
We needed to get our web and database development teams trained on Cassandra, we used DataStax Training and had them onsite to not only deliver training but to answer questions and give guidance on how to setup our column families.
Training
We had a onsite 2 day class delivered by Tupshin Harper from DataStax. He did an excellent
job of getting us up to speed, and answering all questions about NoSQL basics, how to attack some of the problems we are looking to solve, and how to use Hive/Pig.
Infrastructure
Our initial setup was development and QA environment single machine installations of Cassandra. This allowed us to start developing and getting used to how to work with Cassandra, CQL and Fluent Cassandra (we are a .Net shop, expanding into using more open source tools), without having to worry about maintaining a multiple instance setup.
We are now building the staging and production environments both of which have multiple nodes in the clusters. Another wrinkle we had to overcome was the staging and production environment are locked down, so I did not have internet access on those instances to perform a typical install of DataStax Enterprise. To solve this problem we created an internal YUM repository, and mirrored the RedHat, and DataStax repos. Now we can use YUM to install and solve all of the dependency issues. Doing the install this way we did have to manually edit a few files, generate node tokens by hand, and bring the cluster up first then use OpsCenter to install the opscenter-agent on each node.
Cassandra 1.2 for DataStax Enterprise
Cassandra 1.2 for DataStax Enterprise, once it is released, brings virtual nodes and cql3, which has a binary protocol, and Collection columns (collections set, list and map). Features that we are prepared to take full advantage of once they are released to DataStax Enterprise.