Keyspace

5 min to complete

Keyspace

A Keyspace is a top-level container that stores tables with attributes that define how data is replicated on nodes. It defines a number of options that apply to all the tables it contains, most prominently of which is the replication strategy used by the Keyspace.

A keyspace is comparable to the concept of a database Schema in the relational world.  Since the keyspace defines the replication factor of all underlying tables, if we have tables that require different replication factors we would store them in different keyspaces.

To create a Keyspace we use the CREATE KEYSPACE command (don’t do this yet, hands-on example later on).

CREATE KEYSPACE Pets_Clinic WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};

The Replication Strategy determines on which nodes replicas are placed.  More about Replication Strategies here.

Keep in mind that SimpleStrategy should not be used in production.

Data replication ensures there is no single point of failure. Replication means storing copies of data on multiple nodes. This means that even if one node goes down the data will still be available. It ensures reliability and fault tolerance. The number of copies of the data is defined by the Replication Factor.

A replication factor of 3 (RF=3), as in the example above, means that 3 copies of the data are stored at all times. Depending on the RF a user sets for the keyspace, the coordinator node will then share the data with other nodes, called replicas, to create copies of the data for fault tolerance.

More information about high availability,  replication and consistency can be found in this lesson.

To summarize, Keyspaces contain Tables which contain data.

This is also covered in depth in the docs website.

Hands On

Start a single instance and call it ScyllaU:

docker run --name scyllaU -d scylladb/scylla:4.1.0

Notice that some files might be downloaded in this step. After waiting for a few seconds, we’ll verify that the cluster is up and running with the Nodetool Status command:

docker exec -it scyllaU nodetool status

The node scyllaU has a UN status. U means up, and N means normal. Read more about Nodetool Status Here.

Finally we use the CQL Shell to interact with Scylla:

docker exec -it scyllaU cqlsh

The CQL Shell allows us to run Cassandra Query Language commands on Scylla. Now create the Keyspace:

CREATE KEYSPACE Pets_Clinic WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};

Now identify the context for the next operations as the created keyspace:

use Pets_Clinic; 

 

To report this post you need to login first.