Join Sheeri Cabral for an in-depth discussion in this video Cassandra storage engine overview and installation, part of MariaDB for MySQL Users.
Many database environments have more than one type of database. MariaDB's CONNECT storage engine is very useful at connecting to other relational database management systems. However, you may have some NoSQL databases in your environment, like Cassandra, that the CONNECT storage engine cannot access. Cassandra has a limited query language called CQL, which does not allow JOINS nor filters on columns that are not indexed. If CQL is too limited for you, you may find yourself wishing you could use SQL. MariaDB has a Cassandra storage engine that enables you to interact with an existing Cassandra cluster from inside a MariaDB.
Like a relational database, Cassandra has rows and columns but the objects that holds the columns and rows is called a column family, and is not as strict with a schema as relational databases are. With a Cassandra storage engine, we can create a MariaDB table that looks like a Cassandra column family. If you are using Cassandra 1.2, there's a limitation with MariaDB's Cassandra storage engine. Only column family is defined using the attribute with compact storage are valid. I will assume that if you want to connect to Cassandra, you already have it running, and will not go through the steps on how to install and configure a Cassandra cluster. The Cassandra storage engine for MariaDB does not ship with the MariaDB server program. There is a separate package to install this. Check the MariaDB knowledge base at www.mariadb.org to find out how to get the proper package for your distribution. I am using CentOS. So I'll do a sudo yum install MariaDB-cassandra-engine.
It looks like I already have the package installed. Let's double check that we have the correct plugin. From the command line, I will run a MySQL command. So I gave it the username and password, and then I use -e to execute a query. And my query's going to be SHOW VARIABLES LIKE plugin directory. My plugin directory is usr/lib64/mysql/plugin. So I'm going to do a directory listing. So ls to list the directory, -1 so it's one line per file in the directory, usr/lib64/mysql/plugin. If the installation of the Cassandra storage engine worked, you should have the file hacassandra.so in your plugin directory.
To actually install the plugin we have to go inside of MySQL. So again, I'll connect to MySQL with the username and password. And then I'm going to clear the screen with Ctrl+L. To install the plugin, we type install plugin Cassandra, and the SO name is ha_cassandra. It will look in the plugins directory for a file called hacassandra.so. I got an error that says function Cassandra already exists, which is what you get if you already have a plugin installed.
Now that it's installed, let's look on how to configure the Cassandra storage engine. One of the more interesting features of Cassandra is that you can choose the level of consistency you want. There are ten read consistency levels in Cassandra, and more than ten write consistency levels. You can change the read consistency in MariaDB to match the underlying Cassandra data store with the system variable cassandra_read_consistency. Similarly, you can change the write consistency with cassandra_write_consistency. Because MariaDB has to read from a remote place, it is possible that Cassandra will time out as unavailable.
If Cassandra times out or is otherwise unavailable, MariaDB will retry a few times just in case the problem is temporary. You can control the number of times to retry with the cassandra_failure_retries system variable. The default is 3. To find out how many times we have exceptions from Cassandra they're are two status variables. The first status variable, cassandra_timeout_exceptions, counts how many times Cassandra timed out.
The second status variable, cassandra_unavailable_exceptions, counts how many times Cassandra was unavailable. I've explained the Cassandra storage engine in MariaDB, and have shown you how to install it. And I've shown the system and status variables for fault tolerance and consistency when accessing Cassandra tables.
- Why use dynamic columns?
- Creating, updating, and querying dynamic columns
- Installing the CONNECT storage engine
- Connecting to remote data
- Connecting to CSV, INI, and XML files
- Using PIVOT tables
- Accessing database metadata
- Working with the Cassandra storage engine