DataStax Developer Blog

DataStax C/C++ Driver Beta 2 Released

By Michael Penick - Alex Popescu -  July 17, 2014 | 0 Comments

We are happy to announce the beta 2 of the C/C++ driver for Apache Cassandra. Starting with this version, the C++ driver supports both version 1 and 2 of the CQL Binary Protocol making it compatible with both Cassandra 1.2 and 2.0. This beta is also adds support for auto-pagination (when using Cassandra 2.0), an improved configuration API, and fixes all the bugs reported in the first beta. Last, but not least we have heard your feedback about expanding support for older compilers.

What’s new

Support for Cassandra 1.2

We promised it in the first beta, now it’s here. The C++ beta2 supports now both Cassandra 1.2 and 2.0. This feature works automatically without changing any options. Internally, we default to using protocol version 2 and automatically downgrade when we detect that your cluster is running Cassandra 1.2. It can also be explicitly set using the cass_cluster_set_protocol_version() method which will avoid extra round trips required to automatically downgrade the protocol.

Automatic paging with Cassandra 2.0

Cassandra 2.0 introduced support for auto-pagination of result sets. The driver now supports this feature:

  /* Initialize cluster and connect session */

  const CassResult* result = NULL;
  CassFuture* future = NULL;

  CassString query =
      cass_string_init("SELECT * FROM posts_by_day WHERE day = 'Wednesday'");

  CassStatement* statement = cass_statement_new(query, 0);

  /* To enable paging set the page size */
  cass_statement_set_paging_size(statement, 1000);

  future = cass_session_execute(session, statement);

  /* Check future for error */

  result = cass_future_get_result(future);

  process_blog_posts(result);

  /* Check to see if there are any more pages left */
  while (cass_result_has_more_pages(result)) {

    /* Set the paging state to get the next set of results */
    cass_statement_set_paging_state(statement, result);

    cass_result_free(result);

    future = cass_session_execute(session, statement);

    /* Check future for error */

    result = cass_future_get_result(future);

    process_blog_posts(result);
  }

  cass_result_free(result);

Improved configuration API

We started with a generic `setopt` based API for configuring a cluster. This is a common approach used by other C libraries, but we have realized that this approach is more verbose to use, error prone, and difficult to document properly. We now provide dedicated `set` methods for configuring cluster options. The new API can be seen here.

Along with this change, now you can also specify batch type on batches, serial consistency on statements, and use a custom log callback. Specifying a log callback allows your application to customize log formatting and write to different output sources. By default the driver logs to stdout.

Removed C++11 dependency

This version of the driver has been successfully compiled with GCC 4.1.2 and MSVC 2010. The previous version of the driver required more up-to-date compilers, GCC 4.6+ and MSVC 2013, because we were using C++11 internally.

C++11 is awesome, but compilers that support those features are not always available on older platforms. One of the main goals of this driver is to support a wide variety of platforms, and the internal dependency on C++11 was not allowing us to accomplish this goal. The simple part of this change was removing C++11 syntax, but the more challenging part was finding portable alternatives to replace the functionality provided by C++11. For multithreaded synchronization primitives we used libuv’s uv_mutex_t and uv_cond_t in place of std::mutex and std::condition_variable. We replaced std::atomic with similar functionality from Boost, but instead of requiring Boost as an external dependency we have included a small subset in the driver’s source code using Boost’s BCP utility. By removing C++11 we have made the driver much more portable and that has been accomplished without adding any new external dependencies.

Final thoughts

  • Even though this is a beta release it has been thoroughly tested. We have updated and added several tests/examples to cover the functionality introduced by this release.
  • In a quick (pseudo) benchmark that we ran on our desktop workstations, we’ve seen approximately 50k queries per second. This is not a real benchmark, but a rough and initial estimation of throughput performance.
  • The source code is available on GitHub: https://github.com/datastax/cpp-driver/
  • Here are some additional resource to help you get started:


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>