A Shard-Aware Scylla C/C++ Driver

Why?

cqlsh> SELECT address, port, client_type, shard_id FROM system.clients; address   | port  | client_type | shard_id
-----------+-------+-------------+----------
127.0.0.1 | 46730 | cql | 2
127.0.0.1 | 46732 | cql | 3
127.0.0.1 | 46768 | cql | 0
127.0.0.1 | 46770 | cql | 1
(4 rows)

How?

Installation

# Installation: CentOS 7
sudo yum install -y epel-release
sudo yum -y install libuv openssl zlib
wget https://github.com/scylladb/cpp-driver/releases/download/2.15.2-1/scylla-cpp-driver-2.15.2-1.el7.x86_64.rpm https://github.com/scylladb/cpp-driver/releases/download/2.15.2-1/scylla-cpp-driver-devel-2.15.2-1.el7.x86_64.rpm
sudo yum localinstall -y scylla-cpp-driver-2.15.2-1.el7.x86_64.rpm scylla-cpp-driver-devel-2.15.2-1.el7.x86_64.rpm
# Installation: Ubuntu 18.04
wget https://github.com/scylladb/cpp-driver/releases/download/2.15.2-1/scylla-cpp-driver_2.15.2-1_amd64.deb https://github.com/scylladb/cpp-driver/releases/download/2.15.2-1/scylla-cpp-driver-dev_2.15.2-1_amd64.deb
sudo apt-get update
sudo apt-get install -y ./scylla-cpp-driver_2.15.2-1_amd64.deb ./scylla-cpp-driver-dev_2.15.2-1_amd64.deb

Example

// conn.cpp - demonstration of advanced shard selection in C++
#include
#include
#include
#include

int main(int argc, char* argv[]) {
CassCluster* cluster = cass_cluster_new();
CassSession* session = cass_session_new();

cass_cluster_set_num_threads_io(cluster, 2);
cass_cluster_set_contact_points(cluster, "127.0.0.1");
cass_cluster_set_core_connections_per_host(cluster, 7);
// Now enable advanced shard-awareness
cass_cluster_set_local_port_range(cluster, 50000, 60000);

CassFuture* connect_future = cass_session_connect(session, cluster);

if (cass_future_error_code(connect_future) == CASS_OK) {
std::cout << "Connected\n";
std::this_thread::sleep_for(std::chrono::seconds(60)); // [1]
} else {
std::cout << "Connection ERROR\n";
}

// Cleanup
cass_future_free(connect_future);
cass_session_free(session);
cass_cluster_free(cluster);
}
cqlsh> SELECT address, port, client_type, shard_id FROM system.clients;

address | port | client_type | shard_id
-----------+-------+-------------+----------
127.0.0.1 | 37534 | cql | 0
127.0.0.1 | 37536 | cql | 1
127.0.0.1 | 38207 | cql | 4
127.0.0.1 | 50000 | cql | 0
127.0.0.1 | 50001 | cql | 1
127.0.0.1 | 50002 | cql | 2
127.0.0.1 | 50003 | cql | 3
127.0.0.1 | 50004 | cql | 4
127.0.0.1 | 50005 | cql | 5
127.0.0.1 | 50006 | cql | 6
127.0.0.1 | 50007 | cql | 7
127.0.0.1 | 50008 | cql | 0
127.0.0.1 | 50009 | cql | 1
127.0.0.1 | 50010 | cql | 2
127.0.0.1 | 50011 | cql | 3
127.0.0.1 | 50012 | cql | 4
127.0.0.1 | 50013 | cql | 5
127.0.0.1 | 50014 | cql | 6
127.0.0.1 | 50015 | cql | 7
(19 rows)

Summary

--

--

--

The monstrously-fast NoSQL database.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Sales Support: A Framework

An XY axis graph that depicts 4 quadrants… with 1 customer to many customers on X, and 1 sales person to many sales people Y

Dyno 🦕 : AWS, Swifter

Performing Data Analysis Of Meteorological Data

Advanced SQL (part 4): Stored Procedure

Docker: Building Images for Multiple Architectures

How to prepare for and ace your assessment on Coderbyte

Creating Blog site using Slackbit, GatsbyJS and DEV -1

Creating a First Amazon Echo app using AWS lambda and the Alexa Skills Kit

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ScyllaDB

ScyllaDB

The monstrously-fast NoSQL database.

More from Medium

Step-by-step instruction: How to create an NFT collection using Golang and Ethereum (IPFS)

We are more than 75,000 people (stars 🌟) — awesome-go

GitHub repository avelino/awesome-go

How to find Min or Max value in a Stack with Go

ChitChat: Open source, decentralized cluster membership in Rust